Search Operations PHP- API (Documentation typo?)

Hello everyone!

I am pretty new to Elasticsearch so maybe this is a newbie question but it took me some time to make search queries work in PHP - API.

As per in the documentation (https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_search_operations.html#_a_more_complicated_example) the correct way to construct a "boolean query that contains both a filter and a query" is this:

$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'body' => [
        'query' => [
            'bool' => [
                'filter' => [
                    'term' => [ 'my_field' => 'abc' ]
                ],
                'query' => [
                    'match' => [ 'my_other_field' => 'xyz' ]
                ]
            ]
        ]
    ]
];

But every time I try this way the following error is displayed:

Fatal error: Uncaught exception 'Elasticsearch\Common\Exceptions\BadRequest400Exception' with message '{"error":{"root_cause":[{"type":"parsing_exception","reason":"[bool] query does not support [query]","line":1,"col":92}],"type":"parsing_exception","reason":"[bool] query does not support [query]","line":1,"col":92},"status":400}'

Same error in Kibana:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[bool] query does not support [query]",
        "line": 7,
        "col": 23
      }
    ],
    "type": "parsing_exception",
    "reason": "[bool] query does not support [query]",
    "line": 7,
    "col": 23
  },
  "status": 400
}

The only way it worked for me is changing the "query" term by "must":

$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'body' => [
        'query' => [
            'bool' => [
                'filter' => [
                    'term' => [ 'my_field' => 'abc' ]
                ],
                'must' => [
                    'match' => [ 'my_other_field' => 'xyz' ]
                ]
            ]
        ]
    ]
];

Am I doing something wrong or it is maybe a documentation issue?

Many thanks!

Juan.

What version are you using?

Sorry, I completely forgot to mention it. I'm currently in 5.2.1.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.