Class not found for ElasticsearchDSL builder

346 Views Asked by At

I'm getting the error 'PHP Fatal error: Class 'Search' not found'. For the following query:

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

But when I run the following query it works fine, which makes me wonder is the issue with my namespaces, which from the source files it looks like has changed. Any thoughts?

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

There are 0 best solutions below