# Elasticsearch php client search and range query

**URL:** <https://discuss.elastic.co/t/elasticsearch-php-client-search-and-range-query/96919>\
**Category:** Elasticsearch\
**Created:** [August 14, 2017, 7:20am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-search-and-range-query/96919 "2017-08-14T07:20:48Z")\
**Posts on this page:** 4\
**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 14, 2017, 7:20am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-search-and-range-query/96919/1 "2017-08-14T07:20:48Z")

</div>

I am trying to write a query which can search a particular word in a field in between the mentioned dates. So, I should use search and range query. I have written a query but I think I am doing something wrong.

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

Can anyone help me with this?  
Thanks,  
Akhil.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 14, 2017, 7:33am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-search-and-range-query/96919/2 "2017-08-14T07:33:51Z")

</div>

Hey,

can you explain why you are thinking that you are wrong? What happens when you execute this query? Is there an error message? Are wrong documents being returned? Are those documents correctly indexed with date fields? Which Elasticsearch version is this? Have you tried to reproduce your example with curl/plain HTTP and provide this query as well so others can help?

---

<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, 7:55am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-search-and-range-query/96919/3 "2017-08-14T07:55:45Z")

</div>

I am using elasticsearch 5.4.1 Normal curl command works fine and gives the correct results. Index and mapping are correct.  
I am getting this error  
PHP Fatal error: Uncaught exception 'Elasticsearch\Common\Exceptions\BadRequest400Exception' with message '{"error":{"root\_cause":[{"type":"parsing\_exception","reason":"[match] malformed query, expected [END\_OBJECT] but found [FIELD\_NAME]","line":1,"col":63}],"type":"parsing\_exception","reason":"[match] malformed query, expected [END\_OBJECT] but found [FIELD\_NAME]","line":1,"col":63},"status":400}' in /home/akhil/Documents/june/elastic/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:610

Stack trace:  
#0 /home/akhil/Documents/june/elastic/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(273): Elasticsearch\Connections\Connection-\>process4xxError(Array, Array, Array)  
#1 /home/akhil/Documents/june/elastic/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\Connections\Connection-\>Elasticsearch\Connections{closure}(Array)

I am not able to understand this. I shall be thankful to you Alex if you can help me with this.

---

<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, 7:55am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-search-and-range-query/96919/4 "2017-09-11T07:55:53Z")

</div>

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