elasticsearch/elasticsearch — Issue #1621: Simplify filter on date facet results
Author: ahfeel
Created: 2012-01-18 14:32:18+00:00
State: open

A date_histogram facet, being provided with an interval (let's say month) returns entries using millisecond timestamps like this:

"entries"=>[
{"time"=>1325376000000, "count"=>4},
{"time"=>1325378000000, "count"=>2}
]

The problem with the current filter API is that if you want to allow the user to filter on a given month, things can be pretty hard while all the logic is present in elasticsearch.

Right now, the only API to filter on the given month is a range filter as:

"filter" : {
"range" : {
"date" : {
"from" : "1325376000000",
"to" : "XXXXXXXX",
"include_lower" : true,
"include_upper" : false
}
}
}

Computing the "to" can be very tricky when dealing with months and years. While some language do provide helpers for that, I suggest an addition to the range API to be able to give back the interval instead:

"filter" : {
"range" : {
"date" : {
"from" : "1325376000000",
"interval (or duration)" : "month",
"include_lower" : true,
"include_upper" : false
}
}
}