# Watcher email action: How to include search query in email body or attachment

**URL:** <https://discuss.elastic.co/t/watcher-email-action-how-to-include-search-query-in-email-body-or-attachment/48723>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [April 28, 2016, 6:32pm UTC](https://discuss.elastic.co/t/watcher-email-action-how-to-include-search-query-in-email-body-or-attachment/48723 "2016-04-28T18:32:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eeivin](https://avatars.discourse-cdn.com/v4/letter/e/90ced4/32.png) [@eeivin](https://discuss.elastic.co/u/eeivin)\
**Post date:** [April 28, 2016, 6:32pm UTC](https://discuss.elastic.co/t/watcher-email-action-how-to-include-search-query-in-email-body-or-attachment/48723/1 "2016-04-28T18:32:37Z")

</div>

I have the following email action

"actions" : {  
"watcher\_email" : {  
"email": {  
"account": "outlook\_account",  
"to": "'[testUser@testDomain.com](mailto:testUser@testDomain.com)'",  
"subject" : "Watcher Alert: {{ctx.payload.hits.total}} log entries --- severity: Fatal",  
"body" : "Watcher "{{ctx.watch\_id}}" Encountered {{ctx.payload.hits.total}} log entries, see attached data",  
"attachments" : {  
"incidentData.json" : {  
"data" : {  
"format" : "json"  
}  
}  
},  
"priority" : "high"  
}  
}  
}

Is there a way to also include search query in email body or attachment?

Thank you for your help,  
Eric

---

<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:** [April 29, 2016, 11:26am UTC](https://discuss.elastic.co/t/watcher-email-action-how-to-include-search-query-in-email-body-or-attachment/48723/2 "2016-04-29T11:26:20Z")

</div>

Hey,

you cannot include the search query. however when you only want to include the term that searched for, you could put additional info in the `metadata`, which is part of the attachment data. You could even reuse that info in your query, by using a search template and referring to the metadata in the params.

--Alex

---

<div class="post-metadata">

**Author:** ![eeivin](https://avatars.discourse-cdn.com/v4/letter/e/90ced4/32.png) [@eeivin](https://discuss.elastic.co/u/eeivin)\
**Post date:** [April 29, 2016, 4:13pm UTC](https://discuss.elastic.co/t/watcher-email-action-how-to-include-search-query-in-email-body-or-attachment/48723/3 "2016-04-29T16:13:26Z")

</div>

That's great. Thank you for your help.

Is there a way to insert a new line "\n" in the email "body" element?

---

<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/watcher-email-action-how-to-include-search-query-in-email-body-or-attachment/48723/4 "2017-07-06T13:45:48Z")

</div>


