A specific histogram facet that can work with date field types enhancing it over the regular histogram facet. Here is a quick example:
{
"query" : {
"match_all" : {}
},
"facets" : {
"histo1" : {
"date_histogram" : {
"field" : "field_name",
"interval" : "day"
}
}
}
}
The interval allows to set the interval at which buckets will be created for each hit. It allows for the constant values of year, month, week, day, hour, minute.
The specific constant values also support setting rounding by appending : to it, and then the rounding value. For example: day:ceiling. The values are:
It also support time setting like 1.5h (up to w for weeks).
By default, times are stored as UTC milliseconds since the epoch. Thus, all computation and “bucketing” / “rounding” is done on UTC. It is possible to provide a time_zone value, which will cause all computations to take the relevant zone into account. The time returned for each bucket/entry is milliseconds since the epoch of the provided time zone.
The zone value accepts either a numeric value for the hours offset, for example: `time_zone” : -2. It also accepts a format of hours and minutes, like “time_zone” : “-02:30”. Another option is to provide a time zone accepted as one of the values listed “here <http://joda-time.sourceforge.net/timezones.html>`_.
The date_histogram facet allows to use a different key (of type date) which controls the bucketing, with a different value field which will then return the total and mean for that field values of the hits within the relevant bucket. For example:
{
"query" : {
"match_all" : {}
},
"facets" : {
"histo1" : {
"histogram" : {
"key_field" : "timestamp",
"value_field" : "price",
"interval" : "day"
}
}
}
}
A script can be used to compute the value that will then be used to compute the total and mean for a bucket. For example:
{
"query" : {
"match_all" : {}
},
"facets" : {
"histo1" : {
"histogram" : {
"key_field" : "timestamp",
"value_script" : "doc['price'].value * 2",
"interval" : "day"
}
}
}
}