Elasticsearch sum_bucket, strip intermediary aggregation from result

不想你离开。 提交于 2021-01-28 04:10:07

问题


I have the following query where

  • I execute a first term aggregation that returns a large number of buckets
  • then execute a metric aggregation on this bucket (avg in this example)
  • and finally a sum_bucket aggregation

When I run this query, the output contains all the intermediary my_huge_bucket.my_huge_bucket_metric results but I am only interested by the sum_bucket metric.

Is there a way to strip the intermediary aggregation from the result?

{
  "size": 0,
  "aggs": {
    "my_sum_bucket": {
      "sum_bucket": {
        "buckets_path": "my_huge_bucket.my_huge_bucket_metric"
      }
    },
    "my_huge_bucket": {
      "terms": {
        "field": "some_field",
        "size": 0
      },
      "aggs": {
        "my_huge_bucket_metric": {
          "avg": {
            "field": "some_field"
          }
        }
      }
    }
  }

}

回答1:


Just found out about the filter_path options that does exactly what I am looking for

https://www.elastic.co/guide/en/elasticsearch/reference/2.3/common-options.html#_response_filtering



来源:https://stackoverflow.com/questions/36361271/elasticsearch-sum-bucket-strip-intermediary-aggregation-from-result

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!