如何在Elasticsearch中使用过滤器聚合获得总和

发布于 2025-02-10 11:38:42 字数 663 浏览 1 评论 0原文

我想计算使用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);

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文