Inside my ElasticSearch index I have a type with a date field. I would like to get statistics for this field, such as which is the maximum and the minimum date, how many documents per month/year were published. I tried the following query:
"query":{
"match_all": {}
},
"facets":{
"histo1":{
"date_histogram":{
"field":"published_date",
"interval":"year"}
}
}
but it returns me data that I do not know how to interpret:
"facets" : {
"histo1" : {
"_type" : "date_histogram",
"entries" : [ {
"time" : -946771200000,
"count" : 23957
}, {
"time" : -915148800000,
"count" : 45362
}, {
"time" : -883612800000,
"count" : 34568
}]
}
I would have expected to see the count for each year, the time value seems like a black box. Am I doing any mistake? I get the same when I try to use month.
Thank you very much!
From the Elasticsearch Reference for Date Histogram Facet:
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 (both pre rounding, and post rounding) 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.
You will need to convert the time
facet values from their milliseconds since the epoch as a post search request operation to get them into a more preferred format.