Watcher Condition: Bucket Size

Hello, does anyone knows how do I get the buckets size from the sub-aggregation buckets "obs1" under the Watcher condition ? Please advise, thanks.

 "aggregations" : {
    "system" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "system-health-check-status",
          "doc_count" : 20,
          "obs1" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "obs1.com",
                "doc_count" : 5
              },
              {
                "key" : "obs2.com",
                "doc_count" : 5
              }
            ]
          }
        }
      ]
    }
  }

If you are only ever expecting a single bucket for system-health-check-status, the simple solution would just be ctx.payload.aggregations.system.buckets.0.obs1.buckets.length ... but if you expect that you would have multiple top level and lower level buckets for your aggregation, then you will have to iterate over each to get the bucket size(s) for each.

1 Like

You can also go with ctx.payload.aggregations.system.buckets.0.obs1.size

1 Like

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