# Incorrect result with date range query in elasticsearch

**URL:** <https://discuss.elastic.co/t/incorrect-result-with-date-range-query-in-elasticsearch/74061>\
**Category:** Elasticsearch\
**Created:** [February 6, 2017, 1:45pm UTC](https://discuss.elastic.co/t/incorrect-result-with-date-range-query-in-elasticsearch/74061 "2017-02-06T13:45:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divya\_Bhardwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divya_bhardwaj/32/15231_2.png) [@Divya\_Bhardwaj](https://discuss.elastic.co/u/Divya_Bhardwaj)\
**Post date:** [February 6, 2017, 1:45pm UTC](https://discuss.elastic.co/t/incorrect-result-with-date-range-query-in-elasticsearch/74061/1 "2017-02-06T13:45:30Z")

</div>

Hi All,

I have been struggling with this query;

```
    "range": {
    "opened_at": {
   "gt": "2017-02-02 00:00:00",
   "time_zone":"-05:00" 

        }
        }

```

but I get the result for:

"opened\_at": "2017-01-06 15:40:04",

the mapping for the field is:

"opened\_at": {  
"type": "date",  
"format": "yyyy-MM-DD HH:mm:ss"  
},

Also, we have nested field with the same name and format under a parent\_field called "abc"  
"abc"  
{  
"type": "text",  
"properties{  
"opened\_at": {  
"type": "date",  
"format": "yyyy-MM-DD HH:mm:ss"  
}  
}  
},

Please let me know where improvement is required.

Best,  
Divya Bhardwaj

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 6, 2017, 1:53pm UTC](https://discuss.elastic.co/t/incorrect-result-with-date-range-query-in-elasticsearch/74061/2 "2017-02-06T13:53:53Z")

</div>

I'm not sure it's related to your problem but the first thing that stands out for me is

```
"format": "yyyy-MM-DD HH:mm:ss"

```

[  
DD is day of year not day of month](http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html). Not sure how that influences parsing given there is conflicting evidence (day of year would already suggest a month which might be at odds with the MM data provided)

---

<div class="post-metadata">

**Author:** ![Divya\_Bhardwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divya_bhardwaj/32/15231_2.png) [@Divya\_Bhardwaj](https://discuss.elastic.co/u/Divya_Bhardwaj)\
**Post date:** [February 10, 2017, 8:25am UTC](https://discuss.elastic.co/t/incorrect-result-with-date-range-query-in-elasticsearch/74061/3 "2017-02-10T08:25:19Z")

</div>

thanks Mark, that really helped

---

<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:** [March 10, 2017, 8:25am UTC](https://discuss.elastic.co/t/incorrect-result-with-date-range-query-in-elasticsearch/74061/4 "2017-03-10T08:25:29Z")

</div>

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