Elasticsearch php client range and search

I am using the following query :
$params = ['index' => '201706', 'type' => 'youtube','body' => ['query' => [ 'bool' => [ 'filter' => ['range' => ['created_at' => [ 'gte'=> '2017-06-25 00:00:00','lte' => '2017-09-30 00:00:00']]], 'query' => [ 'match' => ['description' => 'kashmir']],],] ] ];

And I am getting this error:

PHP 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":119}],"type":"parsing_exception","reason":"[bool] query does not support [query]","line":1,"col":119},"status":400}' in /home/akhil/Documents/june/elastic/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:610

Kindly help me rectify this issue
Thanks,
Akhil

Formatted:

$params = [
  'index' => '201706', 
  'type' => 'youtube', 
  'body' => [
    'query' => [
        'bool' => [
          'filter' => [
            'range' => [
                'created_at' => [
                    'gte' => '2017-06-25 00:00:00',
                    'lte' => '2017-09-30 00:00:00'
                ]
            ]
          ], 
          'query' => [
              'match' => [
                'description' => 'kashmir'
              ]
          ], 
      ],
    ]
  ]
];

The error is basically what it says: the boolean query doesn't support a "query" parameter, which you've added under the "filter" parameter.

Was your intention to make the match query a required component? The allowed parameters to a boolean query are must, must_not, should and filter.

2 Likes

Thanks a ton man!

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