如何在Elasticsearch中使用过滤器聚合获得总和
我想计算使用eLasticsearch的表格未取消的总数。请让我知道我的方法是否正确。请让我知道您的建议。
我尝试了下面的聚合过滤器,该过滤器将所有total_stake的总和返回。
SumAggregationBuilder sumOfTotalStake = AggregationBuilders.sum(TOTAL_STAKE).field(TOTAL_STAKE);
BoolQueryBuilder bqb = boolQuery().mustNot(termQuery("state", "Cancelled"));
// create the filter aggregation and add the sub-aggregation
FilterAggregationBuilder aggregation = AggregationBuilders.filter(TOTAL_STAKE+"New", bqb).subAggregation(sumOfTotalStake);
I wanted to calculate the sum of total_stake which status does not Cancelled as per below mentioned table using elasticsearch. Please let me know whether my approach is correct or not. Please let me know your suggestions as well.
I tried the below aggregation filter which return me the sum of all total_stake.
SumAggregationBuilder sumOfTotalStake = AggregationBuilders.sum(TOTAL_STAKE).field(TOTAL_STAKE);
BoolQueryBuilder bqb = boolQuery().mustNot(termQuery("state", "Cancelled"));
// create the filter aggregation and add the sub-aggregation
FilterAggregationBuilder aggregation = AggregationBuilders.filter(TOTAL_STAKE+"New", bqb).subAggregation(sumOfTotalStake);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论