I need an elasticsearch php client query for range filter


(Akhil Prashar) #1

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


I need an elasticsearch php client query for range and search filter
(David Pilato) #2

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.


(Akhil Prashar) #3

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}'


(David Pilato) #4

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’] ]] ] ]]];

(Akhil Prashar) #5

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?


(David Pilato) #6

Something like:

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

Something like this.

But if score matters, use something like:

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

(Akhil Prashar) #7

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'] ]]]]]]];


(system) #8

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