# Need help with {{ctx.payload.aggregations.bucketAgg.buckets.key : null}} in watcher hence wont trigger email action

**URL:** https://discuss.elastic.co/t/need-help-with-ctx-payload-aggregations-bucketagg-buckets-key-null-in-watcher-hence-wont-trigger-email-action/234785
**Category:** Kibana
**Created:** [May 28, 2020, 5:07pm UTC](https://discuss.elastic.co/t/need-help-with-ctx-payload-aggregations-bucketagg-buckets-key-null-in-watcher-hence-wont-trigger-email-action/234785 "2020-05-28T17:07:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![vdalvi](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@vdalvi](https://discuss.elastic.co/u/vdalvi)
#### Post date: [May 28, 2020, 5:07pm UTC](https://discuss.elastic.co/t/need-help-with-ctx-payload-aggregations-bucketagg-buckets-key-null-in-watcher-hence-wont-trigger-email-action/234785/1 "2020-05-28T17:07:13Z")

</div>

Hi,

I am new to Kibana Watchers and I am facing issues in parsing the desired value to "ctx.payload.aggregations".

I get the below result

```auto
"ctx.payload.aggregations.numberofcmtsId.buckets.count_deriv.value": null

```

My Watcher Query is as below

```auto
{
  "trigger" : {
    "schedule" : { "interval" : "60s" } 
  },
  "input" : {
    "search" : {
      "request" : {
        "indices" : ["snmp-*"],
        "body" : {
          "size":0,
          "query": {
            "range": {
              "timestamp": {
                "gte": "now-90m/m",
                "lte": "now-30m/m"
              }
            }
          },
          "aggs": {
            "every30min": {
              "date_histogram": {
                "field": "timestamp",
                "fixed_interval": "30m",
                "order": {
                  "_key": "desc"
                }
              },
              "aggs": {
                "numberofcmtsId": {
                  "cardinality": {
                    "field": "cmtsId"
                  }
                },
                "count_deriv": {
                  "derivative": {
                    "buckets_path": "numberofcmtsId" 
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "condition" : {
    "compare": {
      "ctx.payload.aggregations.numberofcmtsId.buckets.count_deriv.value" : { "gt" : 10 }
    }
  },
  "actions" : {
  "send_email" : { 
    "throttle_period" : "5m",
    "email" : { 
      "to" : "abc@xyz.com", 
      "subject" : "TEST: CMTS Count Watcher Notification", 
      "body" : "" 
      }
    }
  }
}

```

Can anyone please help on what I am doing wrong in "ctx.payload.aggregations" ? 🙂

---

<div class="post-metadata">

### Author: ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)
#### Post date: [May 30, 2020, 4:53am UTC](https://discuss.elastic.co/t/need-help-with-ctx-payload-aggregations-bucketagg-buckets-key-null-in-watcher-hence-wont-trigger-email-action/234785/2 "2020-05-30T04:53:30Z")

</div>

In this query:

```auto
{
  "size": 0,
  "query": {
    "range": {
      "timestamp": {
        "gte": "now-90m/m",
        "lte": "now-30m/m"
      }
    }
  },
  "aggs": {
    "every30min": {
      "date_histogram": {
        "field": "timestamp",
        "fixed_interval": "30m",
        "order": {
          "_key": "desc"
        }
      },
      "aggs": {
        "numberofcmtsId": {
          "cardinality": {
            "field": "cmtsId"
          }
        },
        "count_deriv": {
          "derivative": {
            "buckets_path": "numberofcmtsId"
          }
        }
      }
    }
  }
}

```

I think the first `numberofcmtsId` agg bucket in the result would not have any value for `count_derive`, right? Derivatives need more than one metric for comparison, since derivatives are a value of difference between 2 metrics.

I'm not sure if you are seeing any error messages, but the issue could be that you have to add a pre-condition to `count_deriv.value` to ensure that it is not null.

For more help, I would suggest reaching out in the Elasticsearch channel of this Discuss forum. But I hope that helps all you need 🙂

-Tim

---

<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: [June 27, 2020, 4:53am UTC](https://discuss.elastic.co/t/need-help-with-ctx-payload-aggregations-bucketagg-buckets-key-null-in-watcher-hence-wont-trigger-email-action/234785/3 "2020-06-27T04:53:40Z")

</div>

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