# Date range query using year

**URL:** https://discuss.elastic.co/t/date-range-query-using-year/146160
**Category:** Elasticsearch
**Created:** [August 27, 2018, 11:03am UTC](https://discuss.elastic.co/t/date-range-query-using-year/146160 "2018-08-27T11:03:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![prasad.ram1431](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@prasad.ram1431](https://discuss.elastic.co/u/prasad.ram1431)
#### Post date: [August 27, 2018, 11:03am UTC](https://discuss.elastic.co/t/date-range-query-using-year/146160/1 "2018-08-27T11:03:10Z")

</div>

Hi All,

I need a date range query for which input will be only year, but in the response, it should contain all the documents within that year like.  
Find the below example,

> "startDate": {  
> "type": "date",  
> "format": "yyyy-MM-dd||yyyy-MM||yyyy"  
> }

While indexing data into ES, this field may contain different values like below,

1. 2017
2. 2017-09
3. 2017-08-23  
So, with the below query, when i am searching i am getting only one document as response.

> {  
> "query":{  
> "range":{  
> "standardisedFinancials.identification.startDate":{  
> "gte":"2014",  
> "lte":"2014"  
> }  
> }  
> }  
> }  
> Could someone please help me on writing the query which gets all the documents containing 2014 as well as 2014-09-20.

Thanks,  
Ram Prasad G

---

<div class="post-metadata">

### Author: ![prasad.ram1431](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@prasad.ram1431](https://discuss.elastic.co/u/prasad.ram1431)
#### Post date: [August 28, 2018, 5:26am UTC](https://discuss.elastic.co/t/date-range-query-using-year/146160/2 "2018-08-28T05:26:39Z")

</div>

Hi,  
Did anyone has any clue on this requirement please.  
Let me know if you need further more information.

Thanks,  
Prasad

---

<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: [August 28, 2018, 5:58am UTC](https://discuss.elastic.co/t/date-range-query-using-year/146160/3 "2018-08-28T05:58:24Z")

</div>

Read [this](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and specifically the "Also be patient" part.

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

---

<div class="post-metadata">

### Author: ![prasad.ram1431](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@prasad.ram1431](https://discuss.elastic.co/u/prasad.ram1431)
#### Post date: [August 28, 2018, 6:03am UTC](https://discuss.elastic.co/t/date-range-query-using-year/146160/4 "2018-08-28T06:03:39Z")

</div>

Thank you very much David, for your valuable information.  
I was expecting something from some of us, as I was in hurry for my project.

Thanks,  
Prasad G

---

<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: [September 25, 2018, 6:03am UTC](https://discuss.elastic.co/t/date-range-query-using-year/146160/5 "2018-09-25T06:03:47Z")

</div>

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