# Date Range filter is not working in the elasticsearch

**URL:** <https://discuss.elastic.co/t/date-range-filter-is-not-working-in-the-elasticsearch/41969>\
**Category:** Elasticsearch\
**Created:** [February 17, 2016, 5:57am UTC](https://discuss.elastic.co/t/date-range-filter-is-not-working-in-the-elasticsearch/41969 "2016-02-17T05:57:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Venkatesh](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@Sandeep\_Venkatesh](https://discuss.elastic.co/u/Sandeep_Venkatesh)\
**Post date:** [February 17, 2016, 5:57am UTC](https://discuss.elastic.co/t/date-range-filter-is-not-working-in-the-elasticsearch/41969/1 "2016-02-17T05:57:19Z")

</div>

The Query i'm using

{"query":  
{  
"filtered":{"query":{"match\_all":{}},  
"filter":{

"and":[  
{ "range":  
{  
"created\_date":{"gte":"2010-05-22","lte":"2012- 05-22", "format":"yyyy-mm-dd"  
}  
}  
},{"not":{"term":{"flag":"Y"}}}]

}}  
}  
}

the created\_date format is "2010-02-19T21:02:02.000Z"

I have given created\_date as the "Date" in the mapping file.  
Can anyone please help me out in this solving this issue.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 17, 2016, 10:46am UTC](https://discuss.elastic.co/t/date-range-filter-is-not-working-in-the-elasticsearch/41969/2 "2016-02-17T10:46:13Z")

</div>

You have a space in lte part. Is that a typo?

It'd be better if you can send a full script which reproduces your issue.

---

<div class="post-metadata">

**Author:** ![Sandeep\_Venkatesh](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@Sandeep\_Venkatesh](https://discuss.elastic.co/u/Sandeep_Venkatesh)\
**Post date:** [February 17, 2016, 3:02pm UTC](https://discuss.elastic.co/t/date-range-filter-is-not-working-in-the-elasticsearch/41969/3 "2016-02-17T15:02:26Z")

</div>

```
{  
   "query":{  
  "filtered":{  
     "query":{  
        "match_all":{  

        }
     },
     "filter":{  
        "and":[  
           {  
              "range":{  
                 "created_date":{  
                    "gte":"2010-05-22",
                    "lte":"2012-05-22",
                    "format":"yyyy-mm-dd"
                 }
              }
           },
           {  
              "not":{  
                 "term":{  
                    "end_dated_flag":"Y"
                 }
              }
           }
        ]
     }
  }
   },
   from:0,
   size:50
}

```

I see records with the date 2010-02-19 in the result

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 17, 2016, 3:53pm UTC](https://discuss.elastic.co/t/date-range-filter-is-not-working-in-the-elasticsearch/41969/4 "2016-02-17T15:53:57Z")

</div>

> [@dadoonet](#):
>
> It'd be better if you can send a full script which reproduces your issue.

It's super important to understand exactly what you are doing.  
Also, please format your code. It makes easier to read.

---

<div class="post-metadata">

**Author:** ![Sandeep\_Venkatesh](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@Sandeep\_Venkatesh](https://discuss.elastic.co/u/Sandeep_Venkatesh)\
**Post date:** [February 17, 2016, 4:00pm UTC](https://discuss.elastic.co/t/date-range-filter-is-not-working-in-the-elasticsearch/41969/5 "2016-02-17T16:00:44Z")

</div>

I'm sorry dadoonet for not indenting the JSON. I have updated the JSON with the proper format. There is no space in the lte value.

---

<div class="post-metadata">

**Author:** ![Sandeep\_Venkatesh](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@Sandeep\_Venkatesh](https://discuss.elastic.co/u/Sandeep_Venkatesh)\
**Post date:** [February 17, 2016, 4:35pm UTC](https://discuss.elastic.co/t/date-range-filter-is-not-working-in-the-elasticsearch/41969/6 "2016-02-17T16:35:22Z")

</div>

I have found out the issue.

The issue was the date format : " **yyyy-mm-dd**"  
It should be " **yyyy-MM-dd**"

Thank you

---

<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 5, 2017, 11:15pm UTC](https://discuss.elastic.co/t/date-range-filter-is-not-working-in-the-elasticsearch/41969/7 "2017-07-05T23:15:39Z")

</div>


