本文主要是介绍Java实现以某栏位Elasticsearch聚合查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
设置筛选条件:
private QueryBuilder setCondititon(Long lowTime,Long upperTime){return boolQuery().must(rangeQuery("time").gte(lowTime).lte(upperTime));
}
设置AGG聚合查询
private TermsAggregation queryByMinute(QueryBuilder queryBuilder){var groupByTeamAgg = terms("group_team").field("team").size(0).order(Terms.Order.count(false)).subAggregation(avg("avg").field("avgNumber"));val searchMinuteQuery = new NativeSearchQueryBuilder().withQuery(queryBuilder).addAggregation(groupByTeamAgg).withIndices("indexes").build();return esService.query(groupByTeamAgg,SearchResult::getAggregations).getHistogramAggregation("group_team");
}
这篇关于Java实现以某栏位Elasticsearch聚合查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!