[英]php code to run elasticsearch query
Im newbie to elasticsearch. 我是Elasticsearch的新手。 I wanted to search mysql dB using elasticsearch. 我想使用elasticsearch搜索mysql dB。 I want and get the result. 我想要并得到结果。 I even installed elastica for this. 我什至为此安装了elastica。 But Im not getting any results from this code: 但是我没有从以下代码得到任何结果:
<?php
require_once '/home/babloo/vendor/autoload.php';
$client = new Elastica_Client();
$index = $client->getIndex('jdbc');
$index->getType('jdbc');
$query_string = new Elastica_Query_QueryString('ashish');
$query_string->setFields(array('name'));
$query = new Elastica_Query($query_string);
$index->refresh();
$searchResults = $index->search($query);
?>
where Am i going wrong? 我要去哪里错了?
Improve the syntax and follow the steps: 1) Do set error reporting ON 改进语法并遵循以下步骤:1)将错误报告设置为“开”
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
session_start();
2) require 'vendor/autoload.php'; 2)需要'vendor / autoload.php'; (Installed using composer) (使用作曲家安装)
3) Create Objects 3)创建对象
$client = new Elasticsearch\Client();
$elasticaClient = new Elastica\Client();
$reque=new Elastica\Request($elasticaClient);
4) Program Example 4)程序示例
$index = $elasticaClient->getIndex('test');
$index->create(array(), true);
$type = $index->getType('test');
$type->addDocument(new Elastica\Document(1, array('username' => 'ruflin')));
$index->refresh();
$query = array(
'query' => array(
'query_string' => array(
'query' => 'ruflin',
)
)
);
//$typee =$reque->GET;
$path = $index->getName() . '/' . $type->getName() . '/_search';
$response = $elasticaClient->request($path, $reque::GET, $query);
$responseArray = $response->getData();
echo "<pre>";
print_r($responseArray);
REFERENCE LINKS 参考链接
b) https://getcomposer.org/doc/01-basic-usage.md H) https://www.digitalocean.com/community/articles/how-to-install-and-use-composer-on-your-vps-running-ubuntu b) https://getcomposer.org/doc/01-basic-usage.md H) https://www.digitalocean.com/community/articles/how-to-install-and-use-composer-on-your -vps-运行-ubuntu
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.