2

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

0 回答 0