I need an elasticsearch php client query for range filter

I am using this query:
$params = ['index' => '201706','type' => 'facebook', 'body' => ['query' => ['bool' => ['must' => ['filter' => ['range' => ['created_at' => ['gte' => '2017-06-25 01:00:00','lte' => '2017-09-30 08:00:00'] ]] ] ]]]];

Please correct this.
Thanks
Akhil

And? What's wrong? Date format issue I guess?

2017-06-25 01:00:00 should may be something like 2017-06-25T01:00:00.

But it would be better if you can test it first with Kibana Dev Console and then if it works, try to fix the PHP problem itself.
If it does not work, share the Kibana script.

I am getting this error :
PHP Fatal error: Uncaught exception 'Elasticsearch\Common\Exceptions\BadRequest400Exception' with message '{"error":{"root_cause":[{"type":"parsing_exception","reason":"no [query] registered for [filter]","line":1,"col":36}],"type":"parsing_exception","reason":"no [query] registered for [filter]","line":1,"col":36},"status":400}'

I see. Remove the must part I think.

Like

$params = [‘index’ => ‘201706’,‘type’ => ‘facebook’, ‘body’ => [‘query’ => [‘bool’ => [‘filter’ => [‘range’ => [‘created_at’ => [‘gte’ => ‘2017-06-25 01:00:00’,‘lte’ => ‘2017-09-30 08:00:00’] ]] ] ]]];
1 Like

Thanks man, it worked. And one more thing if I need to search a particular word in a particular field in a date range, how should I write the query then?

Something like:

{
  "bool": {
    "filter": [
      { "range": ... },
      { "match": ... }
    ]
  }
}

Something like this.

But if score matters, use something like:

{
  "bool": {
    "must": [
      { "match": ... }
    ],
    "filter": [
      { "range": ... }
    ]
  }
}

Hi there, I tried the following query and it is not working

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

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