Elasticsearch php client search and range query

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.

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?

1 Like

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.

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