Getting the keys array from max_bucket output

Hi,

I'm have the following query to get the max_bucket and it's time (as keys). Is there a way to have additional bucket_script that uses the keys from max_bucket.

In the example script below, I have the keys from max_card and I would like to use the keys in info_2 bucket script. Does Elasticsearch have a method to get the keys?

"aggs": {
"day": {
"date_histogram": {
"field": "st",
"interval": "day",
"format": "yyyy-MM-dd HH:mm"
},
"aggs": {
"play_bh": {
"terms": {
"field": "player",
"size": 100
},
"aggs": {
"maxim_hour": {
"date_histogram": {
"field": "st",
"interval": "hour",
},
"aggs": {
"n1": { "sum": { "field": "countA" }},
"d1": { "sum": { "field": "div_2b" }},
"score_card": {
"bucket_script": {
"buckets_path": {
"n1":"kpi_n1",
"d1":"kpi_d1"
},
"script": {
"lang": "painless",
"source": "def card; if (params.d1 == 0) {card = 0.0} else { card = (params.n1/params.d1)} return card"
}
}
}
}
},

        "max_card": {
          "max_bucket": {
            "buckets_path": "maxim_hour>score_card"
          }
        },
        
        "info_2": {
          "bucket_script": {
            "buckets_path": {
              "hr": "max_card"
            },
            "script": {
              "lang": "painless",
              "source": "???"
            }
          }
        }
      }
    }
  }
}

}

Thank you,

Cheers,
Max

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