需求
在项目开发中,需要从elasticsearch中查询日志数据,先统计每一天的日志调用量,然后在每一天的分组聚合基础上,再分组聚合统计成功和失败的日志调用量。文章来源:https://www.toymoban.com/news/detail-721510.html
代码文章来源地址https://www.toymoban.com/news/detail-721510.html
DateHistogramAggregationBuilder aggregationBuilderByTime = AggregationBuilders
.dateHistogram("dateDownStreamRequestTime")
.field("downStreamRequestTime")
.calendarInterval(DateHistogramInterval.DAY)
.offset("-8h")
.minDocCount(0)
.order(BucketOrder.aggregation("_key", true))
.subAggregation(AggregationBuilders.terms("by_status").field("responseState"));
sourceBuilder.aggregation(aggregationBuilderByTime);
到了这里,关于Java Elasticsearch多条件分组聚合查询的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!