How to perform a pipeline aggregation without returning all buckets in Elasticsearch

前端 未结 1 1327
温柔的废话
温柔的废话 2020-12-25 09:44

I\'m using Elasticsearch 2.3 and I\'m trying to perform a two-step computation using a pipeline aggregation. I\'m only interested in the final result of my pipeline aggregat

1条回答
  •  暖寄归人
    2020-12-25 10:28

    I had the same issue and after doing quite a bit of research I found a solution and thought I'd share here.

    You can use the Response Filtering feature to filter the part of the answer that you want to receive.

    You should be able to achieve what you want by adding the query parameter filter_path=aggregations.avg_min_value to the search URL. In the example case, it should look similar to this:

    curl -XPOST 'http://10.10.0.7:9200/test-index/obj/_search?filter_path=aggregations.avg_min_value' -d '{
      "size": 0,
      "query": {
        "match_all": {}
      },
      "aggregations": {
        "key_aggregates": {
          "terms": {
            "field": "key",
            "size": 0
          },
          "aggs": {
            "min_value": {
              "min": {
                "field": "value"
              }
            }
          }
        },
        "avg_min_value": {
          "avg_bucket": {
            "buckets_path": "key_aggregates>min_value"
          }
        }
      }
    }'
    

    PS: if you found another solution would you mind sharing it here? Thanks!

    0 讨论(0)
提交回复
热议问题