Elasticsearch: aggregation min_doc_count for weeks doesn't work Elasticsearch: aggregation min_doc_count for weeks doesn't work elasticsearch elasticsearch

Elasticsearch: aggregation min_doc_count for weeks doesn't work


You can try specifying extended bounds (there's documentation discussing this feature on the official doc page for histogram aggregations). The most relevant nugget from those docs is this:

With extended_bounds setting, you now can "force" the histogram aggregation to start building buckets on a specific min values and also keep on building buckets up to a max value (even if there are no documents anymore). Using extended_bounds only makes sense when min_doc_count is 0 (the empty buckets will never be returned if min_doc_count is greater than 0).

So your aggregation may have to look something like this to force ES to return empty buckets in that range:

{  "aggs": {    "scores_by_date": {      "date_histogram": {      "field": "date",      "format": "yyyy-MM-dd",      "interval": "week",      "min_doc_count": 0,      "extended_bounds" : {        "min" : "2015-01-01",        "max" : "2015-02-23"      }    }  }}