# Range query not working with format

**URL:** <https://discuss.elastic.co/t/range-query-not-working-with-format/131659>\
**Category:** Elasticsearch\
**Created:** [May 14, 2018, 5:53am UTC](https://discuss.elastic.co/t/range-query-not-working-with-format/131659 "2018-05-14T05:53:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Ensslen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steven_ensslen/32/26984_2.png) [@Steven\_Ensslen](https://discuss.elastic.co/u/Steven_Ensslen)\
**Post date:** [May 14, 2018, 5:53am UTC](https://discuss.elastic.co/t/range-query-not-working-with-format/131659/1 "2018-05-14T05:53:35Z")

</div>

Hi all, I think that I've come across a defect.

I have an index with a date field, start\_datetime

This more restrictive query returns data  
GET /\_search  
{  
"query": {  
"range" : {  
"start\_datetime" : {  
"gte": "10-05-2018",  
"lte": "12-05-2018",  
"format": "dd-mm-yyyy"  
}  
}  
}  
}

While this query, which asks for a superset of the previous query, returns nothing:  
GET /\_search  
{  
"query": {  
"range" : {  
"start\_datetime" : {  
"gte": "10",  
"lte": "12",  
"format": "dd"  
}  
}  
}  
}

I get a respoonse for May 10 to 12 of this year, but no data for the 10th to 12th of all months in all year.

Is this behaviour documented or should I open an issue?

Steven

---

<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:** [May 14, 2018, 9:18am UTC](https://discuss.elastic.co/t/range-query-not-working-with-format/131659/2 "2018-05-14T09:18:11Z")

</div>

The format, needs to expand to a specific date in order to be able to execute a range query.

if you need to filter by specific days of the month, the best strategy would be to extract that day into it's own field `day_of_month`, which as a short, and then do a simple range query against that.

--Alex

---

<div class="post-metadata">

**Author:** ![Steven\_Ensslen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steven_ensslen/32/26984_2.png) [@Steven\_Ensslen](https://discuss.elastic.co/u/Steven_Ensslen)\
**Post date:** [May 16, 2018, 12:05am UTC](https://discuss.elastic.co/t/range-query-not-working-with-format/131659/3 "2018-05-16T00:05:10Z")

</div>

Thanks Alex,

I've opened [issue 30634](https://github.com/elastic/elasticsearch/issues/30634) for the documentation. Please comment on that issue with (a link to?) the information that should be in the documentation.

Steven

---

<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:** [June 13, 2018, 12:05am UTC](https://discuss.elastic.co/t/range-query-not-working-with-format/131659/4 "2018-06-13T00:05:11Z")

</div>

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