我收到错误' 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);