如何过滤术语汇总 [英] How to filter terms aggregation

查看:64
本文介绍了如何过滤术语汇总的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我有这样的东西

aggs: {
  categories: {
    terms: {
      field: 'category'
    }
  }
}

,这给了我每个类别中的产品数量。但是我还有其他条件。我需要获取每个类别中尚未售出的产品数量,因此我需要对条款执行过滤。

and this is giving me number of products in each category. But I have additional condition. I need to get number of products in each category which are not sold already, so I need to perform filter on terms somehow.

是否有一些使用聚合框架执行此操作的优雅方法,或者我需要编写过滤查询?

Is there some elegant way of doing this using aggregation framework, or I need to write filtered query?

谢谢

推荐答案

您可以在术语聚合过滤聚合,它的外观应为:(经过测试)

You can merge between Terms Aggregation and Filter Aggregation, and this is how it should look: (tested)

    aggs: {
      categories: {            
        filter: {term: {sold: true}},
        aggs: {
          names: {
            terms: {field: 'category'}
          }
        }
      }
    }

您还可以在过滤器中添加更多条件,希望对您有所帮助。

You can add also more conditions to the filter, I hope this helps.

这篇关于如何过滤术语汇总的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆