Elastic Search Date Range queries


(ama sindhuc) #1

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

     {
      "Id":
    

"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": "",
    },

}


(Andrew[.:at:.]DataFeedFile.com) #2

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

     { 
      "Id": 
    

"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": "", 
    }, 

}


(system) #3