# Watcher add field to payload

**URL:** <https://discuss.elastic.co/t/watcher-add-field-to-payload/269008>\
**Category:** Kibana\
**Created:** [April 1, 2021, 9:45am UTC](https://discuss.elastic.co/t/watcher-add-field-to-payload/269008 "2021-04-01T09:45:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomaszgorka](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@tomaszgorka](https://discuss.elastic.co/u/tomaszgorka)\
**Post date:** [April 1, 2021, 9:45am UTC](https://discuss.elastic.co/t/watcher-add-field-to-payload/269008/1 "2021-04-01T09:45:39Z")

</div>

Hi, I have a watcher that takes people's data as input. If someone is below 21 yo it triggers the watcher and fires an index action. However I now need to add an additional field to the payload, which is "watchername" and just assign some value to it. All watchers will send data to the same index and I need it to differenciate the watchers later in the index, that's why I need the watchers name. I tried some things in the transform: `ctx.payload.hits.hits.put("watchername", "name")`,  
and also

` return [ctx.payload.hits.hits, "watchername": "name"]`

but nothing works. It just could be a hardcoded value that we will set up, it doesn't have to really take the watchers name.  
Any ideas? Thanks in advance

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [April 1, 2021, 5:16pm UTC](https://discuss.elastic.co/t/watcher-add-field-to-payload/269008/2 "2021-04-01T17:16:20Z")

</div>

I assume that you are using the [index action](https://www.elastic.co/guide/en/elasticsearch/reference/current/actions-index.html) of Watcher, with a transform script. That link has an example transform script that is able to modify _every document_ that the watcher is indexing. In the example watcher script from those docs, you could do `"watcherName": "name"` into the \_doc instead of changing severity.

---

<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:** [April 29, 2021, 5:17pm UTC](https://discuss.elastic.co/t/watcher-add-field-to-payload/269008/3 "2021-04-29T17:17:20Z")

</div>

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