Reference Result of Aggregation in Sub-Aggregation

How do I refer to "avg_flight_min" in the Range Aggregation, replacing the hard-coded value of 100:

GET kibana_sample_data_flights/_search
{
  "size": 0,
  "aggs": {
    "avg_flight_min": {
      "avg": {
        "field": "FlightTimeMin"
      }
    },
    "price_ranges": {
      "range": {
        "field": "FlightTimeMin",
        "keyed": true, 
        "ranges": [
          {
            "key": "below_avg", 
            "to": 100
          },
          {
            "key": "above_avg", 
            "from": 100
          }
        ]
      }
    }
  }
}

I am using the Sample Flight Data in this example.

You would need to run two queries for this. First a search for the avg aggregation, than a search for the for the range.

For some use-cases there are pipelines aggregations, that use the output of aggregations as their input.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.