# Watcher Iteration questions

**URL:** https://discuss.elastic.co/t/watcher-iteration-questions/124880
**Category:** Elasticsearch
**Created:** [March 21, 2018, 12:13am UTC](https://discuss.elastic.co/t/watcher-iteration-questions/124880 "2018-03-21T00:13:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jeremy.smith](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@jeremy.smith](https://discuss.elastic.co/u/jeremy.smith)
#### Post date: [March 21, 2018, 12:13am UTC](https://discuss.elastic.co/t/watcher-iteration-questions/124880/1 "2018-03-21T00:13:49Z")

</div>

I wanted to know if there is a way to iterate over the ctx.payload.hits array to get ctx.payload.hits.0.\_source to go to ctx.payload.hits.1.\_source such that I can use 1 watcher to post inidividual slack messages for each hit.

Here is what I have -- I'm fairly new to this... so please let me know of any improvements you notice.

`{ "trigger": { "schedule": { "interval": "15m" } }, "input": { "search": { "request": { "search_type": "query_then_fetch", "indices": ["remedyforce-*"], "types": [], "body": { "size": 100, "query": { "bool": { "must": [{ "match": { "isRush": "true" } }, { "match": { "_type": "ir_or_sr" } }], "filter": [{ "range": { "createdDate": { "gte": "now-6h" } } }] } } } } } }, "condition": { "script": { "inline": "ctx.payload.hits.total > 0", "lang": "painless" } }, "actions": { "notify-slack": { "slack": { "message": { "from": "Rush Notifier", "to": ["#trialauthcodechannel"], "attachments": [{ "title": "Rush Request", "text": " {{#ctx.payload.hits.hits.0._source}}Rush Request was entered. Please check Remedyforce SR {{number}}\n{{/ctx.payload.hits.hits.0._source}}" }] } }`

---

<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: [March 21, 2018, 5:32pm UTC](https://discuss.elastic.co/t/watcher-iteration-questions/124880/2 "2018-03-21T17:32:15Z")

</div>

Hey,

this is currently not supported - you cannot loop through a result set and fire an action for each of the elements in the set. We are currently considering to add this as a feature though.

A current workaround currently could be to send the whole data over to logstash and deal with this over there.

--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: [April 18, 2018, 5:32pm UTC](https://discuss.elastic.co/t/watcher-iteration-questions/124880/3 "2018-04-18T17:32:26Z")

</div>

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