# Referencing a value within a bucket within a bucket

**URL:** <https://discuss.elastic.co/t/referencing-a-value-within-a-bucket-within-a-bucket/292823>\
**Category:** Elasticsearch\
**Created:** [December 23, 2021, 3:26pm UTC](https://discuss.elastic.co/t/referencing-a-value-within-a-bucket-within-a-bucket/292823 "2021-12-23T15:26:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![walshe06](https://avatars.discourse-cdn.com/v4/letter/w/7ea924/32.png) [@walshe06](https://discuss.elastic.co/u/walshe06)\
**Post date:** [December 23, 2021, 3:26pm UTC](https://discuss.elastic.co/t/referencing-a-value-within-a-bucket-within-a-bucket/292823/1 "2021-12-23T15:26:04Z")

</div>

Hi

I am looking to create a watcher alert to trigger if the value within a bucket is above a certain threshold. However the value will vary as it is within a bucket within a bucket. The value is shown in (ctx.payload.per\_15m.buckets.total\_mount\_points)

I've attached the watcher rule below but at the moment it is returning a null value, I assume as the value varies. Can anyone help in how I would pull the differing values for total\_mount\_points out of the rule correctly?

```auto

{
  "trigger": {
    "schedule": {
      "interval": "5m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "metricbeat-*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "filter": [
                {
                  "match_phrase": {
                    "event.dataset": "system.filesystem"
                  }
                },
                {
                  "range": {
                    "@timestamp": {
                      "gte": "{{ctx.trigger.scheduled_time}}||-1h",
                      "lte": "{{ctx.trigger.scheduled_time}}",
                      "format": "strict_date_optional_time||epoch_millis"
                    }
                  }
                }
              ],
              "should": [],
              "must_not": []
            }
          },
          "aggs": {
            "host_name": {
              "terms": {
                "field": "host.name",
                "size": 100
              },
              "aggs": {
                "pull_tag": {
                  "terms": {
                    "field": "tags",
                    "size": 1
                  },
                  "aggs": {
                    "per_15m": {
                      "date_histogram": {
                        "field": "@timestamp",
                        "fixed_interval": "15m"
                      },
                      "aggs": {
                        "total_mount_points": {
                          "cardinality": {
                            "field": "system.filesystem.mount_point"
                          }
                        },
                        "card": {
                          "cumulative_cardinality": {
                            "buckets_path": "total_mount_points"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.per_15m.buckets.total_mount_points": {
        "gte": 3
      }
    }
  }
}

```

---

<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:** [January 20, 2022, 3:26pm UTC](https://discuss.elastic.co/t/referencing-a-value-within-a-bucket-within-a-bucket/292823/2 "2022-01-20T15:26:50Z")

</div>

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