So far i am working on the ES date histogram for getting monthly result, and my query is like
{
"aggs": {
"sales_over_time": {
"date_histogram": {
"field": "date",
"calendar_interval": "1M",
"offset": Cutoff
}
}
}
}
and the return is like
date
1 10978.521 2020-11-20 5995.69
2 11177.911 2020-12-20 199.39
3 11177.911 2021-01-20 0.00
So my question is : what if the date "20" is not exist ? and any error handling from ES? thanks
Jeff
Since it's a monthly date histogram, each bucket must have a date key. That date key is the date of the beginning of the monthly bucket. For instance, 2020-11-20
is the key and the starting date of the bucket starting on that date. In that bucket, you will find all documents whose date is between 2020-11-20
and 2020-12-20
.
Same thing for the last bucket which starts on 2021-01-20
, it will contain all documents starting on that date and going through 2021-02-20
. It doesn't matter whether you have documents whose date field is specifically on those bucket key dates, those keys are just interval bounds.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments