如何进行“分组/最大”查询? [英] How to do "group by / max" query?

查看:96
本文介绍了如何进行“分组/最大”查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按Field1的值对所有记录进行分组,并为每个组计算Field2的最大值。因此,有什么办法可以使最大聚合作用在同一查询中的多个组上?

I need to group all records by a value of Field1, and calculate max value of Field2 for every group. So, is there any way to make max aggregation work over multiple groups within the same query?

推荐答案

GET /yourindex/_search?search_type=count
{
  "aggs": {
    "yourGroup": {
      "terms": {
        "field": "field1",
        "size": 10
      },
      "aggs": {
        "theMax": {
          "max": {
            "field": "field2"
          }
        }
      }
    }
  }
}

这篇关于如何进行“分组/最大”查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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