1

我是弹性搜索的新手。我想使用 elasticsearch 搜索 mysql dB。我想要并得到结果。我什至为此安装了 elastica。但我没有从这段代码中得到任何结果:

<?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);
?>

我哪里错了?

4

1 回答 1

0

改进语法并遵循以下步骤: 1) 将错误报告设置为 ON

   error_reporting(E_ALL);
   ini_set('display_errors', TRUE);
   ini_set('display_startup_errors', TRUE);
   session_start();

2) 需要'供应商/autoload.php';(使用作曲家安装)

3) 创建对象

   $client = new Elasticsearch\Client();
   $elasticaClient = new Elastica\Client();
   $reque=new Elastica\Request($elasticaClient);

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);

参考链接

作曲家

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

于 2014-03-04T06:06:46.783 回答