# Elasticsearch alarm payload not working

**URL:** <https://discuss.elastic.co/t/elasticsearch-alarm-payload-not-working/193670>\
**Category:** Elasticsearch\
**Created:** [August 4, 2019, 10:46am UTC](https://discuss.elastic.co/t/elasticsearch-alarm-payload-not-working/193670 "2019-08-04T10:46:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piyush\_Safaya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piyush_safaya/32/45810_2.png) [@Piyush\_Safaya](https://discuss.elastic.co/u/Piyush_Safaya)\
**Post date:** [August 4, 2019, 10:46am UTC](https://discuss.elastic.co/t/elasticsearch-alarm-payload-not-working/193670/1 "2019-08-04T10:46:23Z")

</div>

I am facing issues when I try to use the Elastic alarm option. I basically want to monitor 1 specific event and once it happens I want contents of the event to be inserted into the new index .

Email works fine for me.

Currently I see a new document is added into a new index but without any payload/specific information.

"actions": {  
"Elasticsearch\_alarm\_3cb812fc-fb09-43e9-bb9e-780f50002815": {  
"name": "Elasticsearch alarm",  
"throttle\_period": "1s",  
"elastic": {  
"priority": "low",  
"stateless": false,  
"message": "{{#ctx.payload.hits.hits}}{ to\_field\_name\_y : {{\_source.to\_field\_name\_y}} , from\_field\_name\_x : {{\_source.from\_field\_name\_x}} }||{{/ctx.payload.hits.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:** [August 5, 2019, 9:57am UTC](https://discuss.elastic.co/t/elasticsearch-alarm-payload-not-working/193670/2 "2019-08-05T09:57:52Z")

</div>

can you share the full example to ease debugging? Thanks!

---

<div class="post-metadata">

**Author:** ![Piyush\_Safaya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piyush_safaya/32/45810_2.png) [@Piyush\_Safaya](https://discuss.elastic.co/u/Piyush_Safaya)\
**Post date:** [August 5, 2019, 10:48am UTC](https://discuss.elastic.co/t/elasticsearch-alarm-payload-not-working/193670/3 "2019-08-05T10:48:26Z")

</div>

{  
"actions": {  
"Elasticsearch\_alarm\_0738406f-20b4-4e06-b9fc-47b588e1a7d2": {  
"name": "Elasticsearch alarm",  
"throttle\_period": "1s",  
"elastic": {  
"priority": "low",  
"stateless": false,  
"message": "{{#ctx.payload.hits.hits}}To {{\_source.to\_field\_name}}, From {{\_source.from\_field\_name}}{{/ctx.payload.hits.hits}}"  
}  
}  
},  
"input": {  
"search": {  
"request": {  
"index": [  
“test-live"  
],  
"body": {  
"size": 0,  
"aggs": {  
"2": {  
"terms": {  
"field": "from\_field\_name.keyword",  
"size": 5,  
"order": {  
"\_count": "desc"  
}  
}  
}  
},  
"version": true,  
"\_source": {  
"excludes":   
},  
"query": {  
"bool": {  
"must": [  
{  
"match\_all": {}  
},  
{  
"query\_string": {  
"query": "to\_field\_name:(123456789) AND from\_field\_name:(711\*)”,  
"analyze\_wildcard": true  
}  
},  
{  
"range": {  
"ingestion\_time": {  
"gte": "now-1m",  
"lte": "now"  
}  
}  
}  
],  
"must\_not":   
}  
},  
"highlight": {  
"pre\_tags": [  
"@kibana-highlighted-field@"  
],  
"post\_tags": [  
"@/kibana-highlighted-field@"  
],  
"fields": {  
"_": {  
"highlight\_query": {  
"bool": {  
"must": [  
{  
"match\_all": {}  
},  
{  
"query\_string": {  
"query": "to\_field\_name:(123456789) AND from\_field\_name:(711_)”,  
"analyze\_wildcard": true  
}  
},  
{  
"range": {  
"ingestion\_time": {  
"gte": "now-1m",  
"lte": "now"  
}  
}  
}  
],  
"must\_not":   
}  
}  
}  
},  
"fragment\_size": 2147483647  
}  
}  
}  
}  
},  
"condition": {  
"script": {  
"script": "payload.hits.total \> 0"  
}  
},  
"trigger": {  
"schedule": {  
"later": "every 15 seconds"  
}  
},  
"disable": false,  
"report": false,  
"title": "watcher\_ym\_new",  
"save\_payload": true,

}

---

<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:** [August 5, 2019, 11:26am UTC](https://discuss.elastic.co/t/elasticsearch-alarm-payload-not-working/193670/4 "2019-08-05T11:26:50Z")

</div>

your script does not work as expected. it must `ctx.payload.hits.total`. Also please share the output of the [Execute Watch API](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/watcher-api-execute-watch.html)

one last tidbit: Please take the time to format your code samples properly. This forum supports markdown and using it will make your posts infinitely more readable. Thanks!

---

<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:** [September 2, 2019, 11:26am UTC](https://discuss.elastic.co/t/elasticsearch-alarm-payload-not-working/193670/5 "2019-09-02T11:26:58Z")

</div>

Closed on September 2, 2019, 11:26am UTC

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