# Any documentation on what ctx looks like?

**URL:** <https://discuss.elastic.co/t/any-documentation-on-what-ctx-looks-like/63211>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 17, 2016, 6:04pm UTC](https://discuss.elastic.co/t/any-documentation-on-what-ctx-looks-like/63211 "2016-10-17T18:04:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![djmcgreal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/djmcgreal/32/52956_2.png) [@djmcgreal](https://discuss.elastic.co/u/djmcgreal)\
**Post date:** [October 17, 2016, 6:04pm UTC](https://discuss.elastic.co/t/any-documentation-on-what-ctx-looks-like/63211/1 "2016-10-17T18:04:51Z")

</div>

Hi all Watchers,

Is there some XPack documentation available that specifies the structure of the ctx object which can be accessed from scripts?

Thanks, Dan.

---

<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 18, 2016, 9:10am UTC](https://discuss.elastic.co/t/any-documentation-on-what-ctx-looks-like/63211/2 "2016-10-18T09:10:04Z")

</div>

Hey,

so the context consists of several pieces

- `id`, an execution id
- `watch_id` - the id of the watch being executed
- `execution_time` - the time the execution started
- `trigger` - information about the trigger that caused this watch to be executed
- `payload` - the payload from the inputs
- `metadata` - optional configured metadata

If you want to find out the contents of all those fields, you could for example use the `logging` action and just output `{{ctx}}`...

--Alex

---

<div class="post-metadata">

**Author:** ![djmcgreal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/djmcgreal/32/52956_2.png) [@djmcgreal](https://discuss.elastic.co/u/djmcgreal)\
**Post date:** [October 18, 2016, 9:21am UTC](https://discuss.elastic.co/t/any-documentation-on-what-ctx-looks-like/63211/3 "2016-10-18T09:21:17Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 24, 2016, 8:57pm UTC](https://discuss.elastic.co/t/any-documentation-on-what-ctx-looks-like/63211/4 "2016-10-24T20:57:36Z")

</div>

FYI this is also documented here - [https://www.elastic.co/guide/en/x-pack/current/how-watcher-works.html#watch-execution-context](https://www.elastic.co/guide/en/x-pack/current/how-watcher-works.html#watch-execution-context)

---

<div class="post-metadata">

**Author:** ![Vitaly\_il](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vitaly_il/32/130964_2.png) [@Vitaly\_il](https://discuss.elastic.co/u/Vitaly_il)\
**Post date:** [May 18, 2017, 11:13am UTC](https://discuss.elastic.co/t/any-documentation-on-what-ctx-looks-like/63211/5 "2017-05-18T11:13:28Z")

</div>

I read these docs and ran a few tests, but I still don't understand how to include some fields or whole message from the query which match watcher condition, into Watcher notification(action).

[https://www.elastic.co/guide/en/x-pack/current/input-search.html](https://www.elastic.co/guide/en/x-pack/current/input-search.html) says: "To load all of the search hits into an email body, use ctx.payload.hits".  
But I received just "ctx.payload.hits is {hits=[], total=1, max\_score=0.0}"

TIA, Vitaly

---

<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:** [May 19, 2017, 7:20am UTC](https://discuss.elastic.co/t/any-documentation-on-what-ctx-looks-like/63211/6 "2017-05-19T07:20:02Z")

</div>

Hey,

the `ctx.payload` field contains the response of the search request you executed in your input. If you execute a HTTP request against any service, this payload will change according to the response.

If a JSON response is returned from a request, this will be converted into nested data structure inside of the payload, like `ctx.payload.hits`, which then contains a hits array. However, your search did not yield any data in that data structure, very likely because you selected `size: 0`.

I hope this helps you to understand the concept behind `ctx.payload`

If there are further questions, please

- open a new thread
- provide the full watch you are testing with

Thanks!

--Alex

---

<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:** [July 6, 2017, 1:41pm UTC](https://discuss.elastic.co/t/any-documentation-on-what-ctx-looks-like/63211/7 "2017-07-06T13:41:56Z")

</div>


