# Watcher Condition: Bucket Size

**URL:** <https://discuss.elastic.co/t/watcher-condition-bucket-size/292635>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [December 22, 2021, 5:00am UTC](https://discuss.elastic.co/t/watcher-condition-bucket-size/292635 "2021-12-22T05:00:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![appleyin1](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@appleyin1](https://discuss.elastic.co/u/appleyin1)\
**Post date:** [December 22, 2021, 5:00am UTC](https://discuss.elastic.co/t/watcher-condition-bucket-size/292635/1 "2021-12-22T05:00:28Z")

</div>

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

```auto
 "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
              }
            ]
          }
        }
      ]
    }
  }

```

---

<div class="post-metadata">

**Author:** ![angelo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/angelo/32/61325_2.png) [@angelo](https://discuss.elastic.co/u/angelo)\
**Post date:** [December 28, 2021, 4:11am UTC](https://discuss.elastic.co/t/watcher-condition-bucket-size/292635/2 "2021-12-28T04:11:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 5, 2022, 3:44pm UTC](https://discuss.elastic.co/t/watcher-condition-bucket-size/292635/3 "2022-01-05T15:44:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 2, 2022, 3:44pm UTC](https://discuss.elastic.co/t/watcher-condition-bucket-size/292635/4 "2022-02-02T15:44:11Z")

</div>

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