# Watcher - include all errors in e-mail

**URL:** <https://discuss.elastic.co/t/watcher-include-all-errors-in-e-mail/117575>\
**Category:** Elasticsearch\
**Created:** [January 30, 2018, 7:44am UTC](https://discuss.elastic.co/t/watcher-include-all-errors-in-e-mail/117575 "2018-01-30T07:44:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pp\_macrix](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pp\_macrix](https://discuss.elastic.co/u/pp_macrix)\
**Post date:** [January 30, 2018, 7:44am UTC](https://discuss.elastic.co/t/watcher-include-all-errors-in-e-mail/117575/1 "2018-01-30T07:44:46Z")

</div>

I've created a watch which shows me how many errors have been written in the log file (which is taken by logstash and then transferred to elasticSearch) for a specific range of time. For now in the email body I send the number of errors, which is configured in the watcher like this:

```
"actions" : {
"send_email" : { 
"email" : { 
"to" : "email@email.com", 
"subject" : "Watcher Notification", 
"body" : "{{ctx.payload.hits.total}} exceptions found.  
}
}
}

```

now I would like to add in the e-mail body the exact exceptions text. How should I do this? I

---

<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:** [January 30, 2018, 9:26am UTC](https://discuss.elastic.co/t/watcher-include-all-errors-in-e-mail/117575/2 "2018-01-30T09:26:50Z")

</div>

you can loop through the hits like hits

```auto
:{{#ctx.payload.hits.hits}}{{_source.my_field}}{{/ctx.payload.hits.hits}}

```

--Alex

---

<div class="post-metadata">

**Author:** ![pp\_macrix](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pp\_macrix](https://discuss.elastic.co/u/pp_macrix)\
**Post date:** [January 30, 2018, 9:50am UTC](https://discuss.elastic.co/t/watcher-include-all-errors-in-e-mail/117575/3 "2018-01-30T09:50:52Z")

</div>

Thanks, it works. Can you please explain how this works? Eventually, how can I include more than one fields? For instance: I want to show the exact error message and also machine on which it occurs

---

<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:** [January 30, 2018, 10:05am UTC](https://discuss.elastic.co/t/watcher-include-all-errors-in-e-mail/117575/4 "2018-01-30T10:05:36Z")

</div>

I think the easiest way is to check out the mustache docs about lists, as this is what we are doing there [https://mustache.github.io/mustache.5.html](https://mustache.github.io/mustache.5.html)

You can basically select anything from inside the payload using the regular dot notation like `foo.bar.baz` that you also know from queries.

---

<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:** [February 27, 2018, 10:05am UTC](https://discuss.elastic.co/t/watcher-include-all-errors-in-e-mail/117575/5 "2018-02-27T10:05:40Z")

</div>

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