I am creating a querybuilder to find records containing first names like jon, leo inside a nested group, but i endup getting an exception.
{"query":{"bool":{"must":[{"nested":{"path":"author","query":{"bool":{"must":[{"terms":{"author.firstName":["jon","leo"]}}]}}}}]}}}
Here is the exception
Fatal error: Uncaught exception 'Elastica\Exception\ResponseException' with message 'failed to create query: {
"bool" : {
"must" : [
{
"nested" : {
"query" : {
"bool" : {
"must" : [
{
"terms" : {
"author.firstNa in C:\Workspace\kcp\vendor\ruflin\elastica\lib\Elastica\Transport\Http.php on line 172
Here is my querybuilder query that i wrote
$firstNames = ['Jon', 'Leo']
$queryBuilder = new QueryBuilder(new Version240());
$queryBuilder->query()
->bool()
->addMust($queryBuilder->query()->nested()
->setPath('author')
->setQuery(
$queryBuilder->query()->bool()
->addMust($queryBuilder->query()->terms(
'author.firstName',
$firstNames
))
)
);
Even the regular query doesnt seems to work
$query = new Query();
$search = new Search($elasticSearchClient);
$authorTerms= new Terms();
$authorTerms->setTerms('author.firstName', ['jon', 'leo']);
$authorTermsBoolQuery = new BoolQuery();
$authorTermsBoolQuery ->addMust($cityState);
$nestedQuery = new \Elastica\Query\Nested();
$nestedQuery->setPath("author");
$nestedQuery->setQuery($authorTermsBoolQuery );
$boolQuery = new BoolQuery();
$boolQuery->addMust($nestedQuery);
$query->setQuery($boolQuery);
$search->setQuery($query);
//echo $numberOfEntries = $search->count();
print_r(json_encode($query->toArray()));
Am i missing something?
Appreciate your help and support
Thanks,
Karthik