# I need an elasticsearch php client query for range filter

**URL:** <https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748>\
**Category:** Elasticsearch\
**Created:** [August 11, 2017, 10:21am UTC](https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748 "2017-08-11T10:21:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akhil\_Prashar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhil_prashar/32/20313_2.png) [@Akhil\_Prashar](https://discuss.elastic.co/u/Akhil_Prashar)\
**Post date:** [August 11, 2017, 10:21am UTC](https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748/1 "2017-08-11T10:21:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 11, 2017, 10:39am UTC](https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748/2 "2017-08-11T10:39:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Akhil\_Prashar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhil_prashar/32/20313_2.png) [@Akhil\_Prashar](https://discuss.elastic.co/u/Akhil_Prashar)\
**Post date:** [August 11, 2017, 10:42am UTC](https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748/3 "2017-08-11T10:42:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 11, 2017, 11:01am UTC](https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748/4 "2017-08-11T11:01:55Z")

</div>

I see. Remove the must part I think.

Like

```auto
$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’] ]] ] ]]];

```

---

<div class="post-metadata">

**Author:** ![Akhil\_Prashar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhil_prashar/32/20313_2.png) [@Akhil\_Prashar](https://discuss.elastic.co/u/Akhil_Prashar)\
**Post date:** [August 11, 2017, 11:09am UTC](https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748/5 "2017-08-11T11:09:58Z")

</div>

> [@dadoonet](#):
>
> $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’] ]] ] ]]];

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?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 11, 2017, 11:49am UTC](https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748/6 "2017-08-11T11:49:04Z")

</div>

Something like:

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

```

Something like this.

But if score matters, use something like:

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

```

---

<div class="post-metadata">

**Author:** ![Akhil\_Prashar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhil_prashar/32/20313_2.png) [@Akhil\_Prashar](https://discuss.elastic.co/u/Akhil_Prashar)\
**Post date:** [August 14, 2017, 3:59am UTC](https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748/7 "2017-08-14T03:59:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 11, 2017, 3:59am UTC](https://discuss.elastic.co/t/i-need-an-elasticsearch-php-client-query-for-range-filter/96748/8 "2017-09-11T03:59:18Z")

</div>

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