How to get values from a bucket using the key(s) of that bucket instead of the index - elasticsearch bucket aggregation - watcher?

Hi team,

I have the below aggregation search query.

  "aggregations" : {
    "test_groups" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "group1",
          "doc_count" : 1,
          "emails" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "abc@xyz.com",
                "doc_count" : 1
              }
            ]
          }
        },
        {
          "key" : "group2",
          "doc_count" : 1,
          "emails" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "xyz@abc.com",
                "doc_count" : 1
              }
            ]
          }
        }
      ]
    }
  }

Now I have to extract the key value for the first bucket under test_groups i.e., "abc@xyz.com". I successfully achieve this by using the following variable.
{{ctx.payload.first.aggregations.test_groups.buckets.0.emails.buckets.0.key}}
I am looking for an alternative of test_groups.buckets.0. and want something like {{ctx.payload.first.aggregations.test_groups.buckets.group1.emails.buckets.0.key}}.
I want to use the key of the buckets instead of its index. Is it possible?

Please help!

Regards,
Souvik

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