# ES query to Perform Search based on the given keywords and get results only within the Specific DateRange

**URL:** <https://discuss.elastic.co/t/es-query-to-perform-search-based-on-the-given-keywords-and-get-results-only-within-the-specific-daterange/9295>\
**Category:** Elasticsearch\
**Created:** [October 9, 2012, 6:38pm UTC](https://discuss.elastic.co/t/es-query-to-perform-search-based-on-the-given-keywords-and-get-results-only-within-the-specific-daterange/9295 "2012-10-09T18:38:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shannu](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@shannu](https://discuss.elastic.co/u/shannu)\
**Post date:** [October 9, 2012, 6:38pm UTC](https://discuss.elastic.co/t/es-query-to-perform-search-based-on-the-given-keywords-and-get-results-only-within-the-specific-daterange/9295/1 "2012-10-09T18:38:05Z")

</div>

Hello All,

I am trying to create a query to perform search based on provided keywords  
and within a specific date range

Query 1 : To Test DateRange -  
curl -XGET '[http://localhost:9200/Index/Type/\_search?pretty=true](http://localhost:9200/Index/Type/_search?pretty=true)' -d  
'{"query":{"range":{"Date":{"from":"2012-10-03T13:52:45","to":"2012-10-03T13:55:00"}}}}'  
Works perfectly fine and the output results are 6 records

* * *

Query 2 : To Test Keyword search -  
curl -XGET '[http://localhost:9200/Index/Type/\_search?pretty=true](http://localhost:9200/Index/Type/_search?pretty=true)' -d  
'{"query":{"match":{"\_all":{"query":"London USA","operator":"or"}}}}'  
Works perfectly fine and the output results are 3 records (Note: The Data  
Range for these 3 records are within the same range as in the 1st query - I  
have manually checked \_source.Date field)

Now to search for these keywords and within the same date range using a  
single Query I should be able to see only 3 records, so to achive this I  
have tried below queries and failed :

Query 3: Just combined Keyword search query 2 and Date Range search query 1  
into single query -  
curl -XGET '[http://localhost:9200/Index/Type/\_search?pretty=true](http://localhost:9200/Index/Type/_search?pretty=true)' -d  
'{"query":{"match":{"\_all":{"query":"London  
USA","operator":"or"}}},"range":{"Date":{"from":"2012-10-03T13:52:45","to":"2012-10-03T13:55:00"}}}'

Result: "error" : "SearchPhaseExecutionException[Failed to execute phase  
[query], nested: SearchParseException[[Index][4]: query[Date:[1349272365000  
TO 1349272500999]],from[-1],size[-1]: Parse Failure [No parser for element  
[match]]]; }]", "status" : 500

* * *

Query 4: Tried to join the queries using "Bool"  
curl -XGET '[http://localhost:9200/Index/Type/\_search?pretty=true](http://localhost:9200/Index/Type/_search?pretty=true)' -d  
'{"query":{"bool":{"must":{"match":{"\_all":{"query":"London  
USA","operator":"or"}}}},"must":{"query":{"range":{"Date":{"from":"2012-10-03T13:52:45","to":"2012-10-03T13:55:00"}}}}}}'

Result: No error, but brings back 6 records that are same as the results  
from the date range query 1.  
So here I think "Bool" will combine the queries but brings back the  
combination of results from both the queries.

* * *

Query 5: Tried using Filter and Match  
curl -XGET '[http://localhost:9200/Index/Type/\_search?pretty=true](http://localhost:9200/Index/Type/_search?pretty=true)' -d  
'{"query":{"range":{"Date":{"from":"2012-10-03T13:52:45","to":"2012-10-03T13:55:00"}}},"filter":{"match":{"\_all":{"query":"London  
USA","operator":"or"}}}}'  
Result: Error for below query: No filter registered for [match]]

* * *

Query 6: Tried using Filter and Term  
curl -XGET '[http://localhost:9200/Index/Type/\_search?pretty=true](http://localhost:9200/Index/Type/_search?pretty=true)' -d  
'{"query":{"range":{"Date":{"from":"2012-10-03T13:52:45","to":"2012-10-03T13:55:00"}}},"filter":{"term":{"\_all":"London  
USA"}}}'  
Output: Zero results

* * *

Query 7: Tried using Filter , Term and query  
curl -XGET '[http://localhost:9200/Index/Type/\_search?pretty=true](http://localhost:9200/Index/Type/_search?pretty=true)' -d  
'{"query":{"range":{"Date":{"from":"2012-10-03T13:52:45","to":"2012-10-03T13:55:00"}}},"filter":{"term":{"\_all":{"query":"London  
USA"}}}}'  
Output Error: [term] filter does not support [query]

Not sure How I can get the query working the way I wanted ?

Any help will be much appreciated.

Regards,  
Shannu.

--

---

<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:** [July 6, 2017, 3:09am UTC](https://discuss.elastic.co/t/es-query-to-perform-search-based-on-the-given-keywords-and-get-results-only-within-the-specific-daterange/9295/2 "2017-07-06T03:09:31Z")

</div>


