# Accessing data of the watch itself

**URL:** <https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 9, 2018, 12:10pm UTC](https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625 "2018-10-09T12:10:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![willemdh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/willemdh/32/16922_2.png) [@willemdh](https://discuss.elastic.co/u/willemdh)\
**Post date:** [October 9, 2018, 12:10pm UTC](https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625/1 "2018-10-09T12:10:43Z")

</div>

Hello,

We are working on some watches and wanted to add the condition threshold in hte output of the html email. Is there a way to access data of the watch itself somehow?

For example if this is the condition:

```
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 2
      }
    }
  }

```

How could we access the threshold key 'ctx.payload.hits.total' and value '2' so we can use this in for example an email action?

Grtz

Willem

---

<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:** [October 9, 2018, 1:37pm UTC](https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625/2 "2018-10-09T13:37:43Z")

</div>

you can use mustache to access parts of the payload like `{{ctx.payload.hits.total}}`

--Alex

---

<div class="post-metadata">

**Author:** ![willemdh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/willemdh/32/16922_2.png) [@willemdh](https://discuss.elastic.co/u/willemdh)\
**Post date:** [October 9, 2018, 2:15pm UTC](https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625/3 "2018-10-09T14:15:48Z")

</div>

Alex,

Yes, I know that, but data from the watch itself, such as the threshold in the condition is not in the payload...

Grtz

Willem

---

<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:** [October 9, 2018, 3:21pm UTC](https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625/4 "2018-10-09T15:21:16Z")

</div>

this is true. The payload represents only the input itself. If you want to do that, you could store the threshold in the [metadata](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-put-watch.html#_request_body_42) and use a `script` condition and do sth like `return ctx.payload.hits.total > ctx.metadata.threshold`

--Alex

---

<div class="post-metadata">

**Author:** ![willemdh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/willemdh/32/16922_2.png) [@willemdh](https://discuss.elastic.co/u/willemdh)\
**Post date:** [October 9, 2018, 8:13pm UTC](https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625/5 "2018-10-09T20:13:16Z")

</div>

Alex,

Ok, I see. And can I use the values in the metadata in the condition? Then I could add

`"metadata" : { "threshold" : "5" }`

And refer to it in the condition?

`"condition" : { "compare" : { "ctx.payload.hits.total" : { "gt" : {{ctx.metadata.threshold}} }}`

Willem

---

<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:** [October 10, 2018, 7:39am UTC](https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625/6 "2018-10-10T07:39:47Z")

</div>

just use a `script` condition like I did above instead of a `compare` and everything will work.

---

<div class="post-metadata">

**Author:** ![willemdh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/willemdh/32/16922_2.png) [@willemdh](https://discuss.elastic.co/u/willemdh)\
**Post date:** [October 11, 2018, 4:54pm UTC](https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625/7 "2018-10-11T16:54:56Z")

</div>

Alex, We were able to use the Metadata in the condition. Thanks!

---

<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:** [November 8, 2018, 5:03pm UTC](https://discuss.elastic.co/t/accessing-data-of-the-watch-itself/151625/8 "2018-11-08T17:03:47Z")

</div>

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