Date range aggregations over different fields

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Date range aggregations over different fields

Michaël Gallego
Hi,

After my first topic here, I've decided to rework my data structure. I have now documents that looks like this:

{
   
"element": "A",
   
"date": "2014-01-01",
   
"valid_until": "2014-02-01"
},
{
   
"element": "A",
   
"date": "2014-02-01",
   
"valid_until": "9999-12-31"
}

The date "9999-12-31" is here to say: "it has not yet expired". There is always range like this, so for a given element "A", date > valid_until can never overlaps. I can therefore count how much element I have by using the pseudo-code like this: COUNT elements WHERE date < date_to_count AND valid_until >= date_to_count

Where "date_to_count" is the date at which I want to count the values for. As I want to calculate this at several points in time, I could either use a date histogram, or a date range aggregation. However, the date range does seem to work only with one kind of field. Ideally, I'd like to be able to do that:

"aggs": {
   
"foo": {
       
"date_range": {
         
"fields": ["date", "valid_until"],
         
"ranges": [
             
{"from": "2014-01-01", "to": {"2014-02-01"}},
              {"from": "2014-02-01", "to": {"2014-03-01"}},
             
{"from": "2014-03-01", "to": {"2014-04-01"}}
         
]
       
}
   
}
}

Where the "date" will be used for "from", and the "valid_until" would be used for "to".

I've tried several other ideas with script, but can't find an efficient way to do it this way :/.

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/03f84120-3017-4f90-9c58-018edb49dc73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Date range aggregations over different fields

Michaël Gallego
Anyone would have a hint on this? :)

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9cbd8a1a-5f3a-4858-bb11-0b27f8f7fd22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.