The structure of my documents is as follows:
{
"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 expired." Such a range always exists, therefore, for a given "A" element, date> valid_until can never overlap. Therefore, I can calculate how many elements I have using a pseudo code, for example: COUNT elements WHERE date <date_to_count AND valid_until> = date_to_count
Where "date_to_count" is the date I want to count the values. Since I want to calculate this at several points in time, I can either use a date histogram or aggregate a date range. However, a date range only works with one field type. Ideally, I would like to be able to do this:
"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"}}
]
}
}
}
"" "from", "valid_until" "to".
script, :/.
, , script /, , , "ctx.to", "context.to", undefined.
!