未找到ElasticsearchDSL构建器的类

时间:2017-02-22 17:26:51

标签: php elasticsearch dsl ongr

我收到错误' PHP致命错误:类'搜索'找不到'。对于以下查询:

use Elasticsearch\ClientBuilder;
use ONGR\ElasticsearchDSL\Search;
use ONGR\ElasticsearchDSL\Query\MatchQuery;
use ONGR\ElasticsearchDSL\Query\BoolQuery;

require 'vendor/autoload.php';
$hosts = ['address'];
$client = ClientBuilder::create()->setHosts($hosts)->build();

//$matchQueryForUser1 = new ONGR\ElasticsearchDSL\Query\MatchQuery('from', 'bob.allen');
$search = new Search();
$matchQueryForUser1 = new MatchQuery("from", "bob.allen");
$matchQueryForUser2 = new MatchQuery("env-from", "bob.allen");
$search->addQuery($matchQueryForUser1, BoolQuery::SHOULD);
$search->addQuery($matchQueryForUser2, BoolQuery::SHOULD);
$search->addParameter("minimum_number_should_match", 1);
$params = [
   'index' => 'mdeveresponsecom196912',
   'type' => 'message',
   'body' => $search->toArray(),
];

$results = $client->search($params);
print_r($results);

但是当我运行以下查询时,它工作正常,这让我想知道我的命名空间的问题,从它看起来的源文件已经改变了。有什么想法吗?

use Elasticsearch\ClientBuilder;
use ONGR\ElasticsearchDSL\Search;
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
require 'vendor/autoload.php';
$hosts = ['address'];
$client = ClientBuilder::create()->setHosts($hosts)->build();

$matchAll = new MatchAllQuery();
$search = new Search();
$search->addQuery($matchAll);

$params = [
   'index' => 'mdeveresponsecom196912',
   'type' => 'message',
   'body' => $search->toArray(),
];

$results = $client->search($params);
print_r($results);

0 个答案:

没有答案