简体   繁体   English

elasticsearch嵌套聚集总值

[英]elasticsearch nested aggregration total value

I have documents with category, respsize, client name etc. as you see in picture below.. 我有类别,重新调整大小,客户名称等的文档,如下图所示。 在此处输入图片说明

I want to get result by dsl query which returns filtered by category and grouped by clientname then total respsize in each category of that user.. here what I tried: 我想通过dsl查询获取结果,该查询返回按类别过滤并按客户端名称分组,然后在该用户的每个类别中重新调整大小。 在此处输入图片说明

But I want respsize of each categories in this result also it should be like: 但是我想在此结果中调整每个类别的大小,也应该像这样:

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

Try this agg ;-) 试试这个agg ;-)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM