1

エラスティックサーチの初心者です。Elasticsearch を使用して mysql dB を検索したかったのです。私は結果を望んでいます。このためにエラスティカもインストールしました。しかし、私はこのコードから何の結果も得ていません:

<?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) エラー報告をオンに設定します。

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

2) 'vendor/autoload.php' が必要です。(composer を使用してインストール)

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-running-ubuntu

于 2014-03-04T06:06:46.783 に答える