# Elastic Search Date Range queries

**URL:** <https://discuss.elastic.co/t/elastic-search-date-range-queries/7649>\
**Category:** Elasticsearch\
**Created:** [May 11, 2012, 2:53am UTC](https://discuss.elastic.co/t/elastic-search-date-range-queries/7649 "2012-05-11T02:53:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ama\_sindhuc](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@ama\_sindhuc](https://discuss.elastic.co/u/ama_sindhuc)\
**Post date:** [May 11, 2012, 2:53am UTC](https://discuss.elastic.co/t/elastic-search-date-range-queries/7649/1 "2012-05-11T02:53:16Z")

</div>

Hello

I am new to elasticsearch and needed some advice around date range  
queries :

The data being indexed contains start time and end time.  
I am planning to map it to a date type and apply rangle queries to  
return values

1. Is the time (below) a valid date format in elasticsearch

2. Can someone please illustrate a way that I can apply range queries  
on indexed data . Example  
i. 1 hour from now or 1 day from now  
ii. From date to To Date

"AAMkADdmMDM4ZDZjLThkYjItNGZkYi05MDMyLWE3YzFkNWJkZWY1MABGAAAAAAAzlc4LRfuqSpTimVdZOAM5BwDVH  
+l4CJ/IRKcSEvbCqPNfAQtPns0bAADVH+l4CJ/IRKcSEvbCqPNfAQtPo/jDAAA=",

```
     "Subject":"Meet xyz in Mountain View",

     "Location":"Red Rock Cafe",

     "StartTime": "Thu Jan 05 01:00:00 PST 2012",

     "EndTime": "Thu Jan 05 02:00:00 PST 2012",

     "Organizer": "make@test.com",

     "Body": "",

     "RequiredAttendees": "",

     "OptionalAttendees": "",
    },

```

}

---

<div class="post-metadata">

**Author:** ![Andrew\_at\_DataFeedFi](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andrew\_at\_DataFeedFi](https://discuss.elastic.co/u/Andrew_at_DataFeedFi)\
**Post date:** [May 11, 2012, 4:23pm UTC](https://discuss.elastic.co/t/elastic-search-date-range-queries/7649/2 "2012-05-11T16:23:02Z")

</div>

Here is an example:

the facet part is optional... you can remove that if you do not need date  
facet.

{  
"from":0,  
"size":0,  
"query":{  
"constant\_score" : {  
"filter" :{  
"bool" :{  
"must" :[  
{  
"range" : {  
"created\_ts" : {  
"from" : "2012-01-01T00:00:00",  
"to" : "2012-03-31T23:59:59",  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
}  
],  
"should" :[  
{  
"term": {  
"RequiredAttendees" : true  
}  
},  
{  
"missing" : { "field" : "OptionalAttendees" }  
}  
]  
}  
}  
}  
},  
"facets" :{  
"created\_ts":{  
"date\_histogram":{  
"field":"created\_ts",  
"interval":"day",  
"post\_zone":4  
}  
}  
}  
}

On Thursday, May 10, 2012 9:53:16 PM UTC-5, ama sindhuc wrote:

> Hello
> 
> I am new to elasticsearch and needed some advice around date range  
> queries :
> 
> The data being indexed contains start time and end time.  
> I am planning to map it to a date type and apply rangle queries to  
> return values
> 
> 1. Is the time (below) a valid date format in elasticsearch
> 
> 2. Can someone please illustrate a way that I can apply range queries  
> on indexed data . Example  
> i. 1 hour from now or 1 day from now  
> ii. From date to To Date
> 
> "AAMkADdmMDM4ZDZjLThkYjItNGZkYi05MDMyLWE3YzFkNWJkZWY1MABGAAAAAAAzlc4LRfuqSpTimVdZOAM5BwDVH
> 
> +l4CJ/IRKcSEvbCqPNfAQtPns0bAADVH+l4CJ/IRKcSEvbCqPNfAQtPo/jDAAA=",
> 
> ```
> "Subject":"Meet xyz in Mountain View", 
> 
> "Location":"Red Rock Cafe", 
> 
> "StartTime": "Thu Jan 05 01:00:00 PST 2012", 
> 
> "EndTime": "Thu Jan 05 02:00:00 PST 2012", 
> 
> "Organizer": "make@test.com", 
> 
> "Body": "", 
> 
> "RequiredAttendees": "", 
> 
> "OptionalAttendees": "", 
> }, 
> 
> ```
> 
> }

---

<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:29am UTC](https://discuss.elastic.co/t/elastic-search-date-range-queries/7649/3 "2017-07-06T03:29:13Z")

</div>


