2

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);
hannahbanana2.0
  • 109
  • 2
  • 10
  • Have you tried moving `require 'vendor/autoload.php';` at the top of your script? – ka_lin Feb 22 '17 at 17:38
  • Yes, tried that. Besides with the match_all query it works fine and the 'require`'vendor/autoload.php';` is in the same place. – hannahbanana2.0 Feb 22 '17 at 17:41
  • 1
    Figured it out. The namespaces have changed for most of the queries. Here's a link for anyone else it might help in the future [link](https://github.com/ongr-io/ElasticsearchDSL/releases/tag/5.0.0) – hannahbanana2.0 Feb 22 '17 at 18:51

0 Answers0