elasticsearch嵌套聚合总值

时间:2015-10-20 16:09:25

标签: elasticsearch

我有类别,重新分配,客户名称等文件,如下图所示。 enter image description here

我希望通过dsl查询得到结果,返回按类别过滤并按客户名分组,然后在该用户的每个类别中重新调整总数。这里我尝试了: enter image description here

但我希望在此结果中重新分配每个类别,它应该是:

"buckets": [
                 {
                    "key": "50",
                    "doc_count": 87,
                    "respsize": 23213                     
                 },
                 {
                    "key": "49",
                    "doc_count": 25,
                    "respsize": 23213
                 }

1 个答案:

答案 0 :(得分:0)

试试这个agg; - )

"aggs": {
    "by_clients": {
      "terms": {
        "field": "clientname"
      },
      "aggs": {
        "by_categories": {
          "terms": {
            "field": "category"
          },
          "aggs": {
            "total_respsize": {
              "sum": {"field": "respsize"}
            }
          }
        }
      }
    }
  }