来自@Val的示例本身并不适合我(我正在使用ElasticSearch 6.2.x的高级API)。虽然有效,但是告诉聚合应该将缺失值处理为0:
final AggregationBuilder<?> dailyDateHistogarm = AggregationBuilders.dateHistogram(AggregationConstants.DAILY) .field("dob") .minDocCount(0) .missing(0) .interval(DateHistogram.Interval.DAY) .subAggregation(aggregateArtifactcount);
是的,你可以使用 “最小文档计数”功能 的 date_histogram 聚合并将其设置为0.这样,您还将获得不包含任何数据的存储桶:
date_histogram
final AggregationBuilder<?> dailyDateHistogarm = AggregationBuilders.dateHistogram(AggregationConstants.DAILY) .field("dob") .minDocCount(0) <--- add this line .interval(DateHistogram.Interval.DAY) .subAggregation(aggregateArtifactcount);