# Iterate over payload fields in Slack action

**URL:** https://discuss.elastic.co/t/iterate-over-payload-fields-in-slack-action/51804
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [June 3, 2016, 2:47pm UTC](https://discuss.elastic.co/t/iterate-over-payload-fields-in-slack-action/51804 "2016-06-03T14:47:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![poznachowski](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@poznachowski](https://discuss.elastic.co/u/poznachowski)
#### Post date: [June 3, 2016, 2:47pm UTC](https://discuss.elastic.co/t/iterate-over-payload-fields-in-slack-action/51804/1 "2016-06-03T14:47:36Z")

</div>

Hi,  
Can I iterate over ctx.payload.hits in Slack action text field for a specific field? I can use index to get specific one (with `ctx.payload.hits.hits.0._id`), but if there are more hits, is it possible to show all ids of the hits?

---

<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: [June 6, 2016, 11:24am UTC](https://discuss.elastic.co/t/iterate-over-payload-fields-in-slack-action/51804/2 "2016-06-06T11:24:45Z")

</div>

Hey,

you should check out the [search template documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html)

See this example

```auto
PUT /foo/bar/first-id
{ "foo":"bar"}

PUT /foo/bar/second-id
{ "foo":"bar"}

PUT _xpack/watcher/watch/my-watch
{
  "trigger": {
    "schedule": {
      "interval": "10s"
    }
  },
  "input": {
    "http": {
      "request": {
        "host": "localhost",
        "port": 9200,
        "path": "/foo/_search"
      }
    }
  },
  "actions": {
    "logging": {
      "logging": {
        "text": "{{#ctx.payload.hits.hits}}{{_id}}|{{/ctx.payload.hits.hits}}"
      }
    }
  }
}

```

results in

```auto
[2016-06-06 13:24:22,548][INFO][xpack.watcher.actions.logging] [Cap 'N Hawk] first-id|second-id|

```

Hope this helps!

--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:45pm UTC](https://discuss.elastic.co/t/iterate-over-payload-fields-in-slack-action/51804/3 "2017-07-06T13:45:11Z")

</div>


