# Watcher payload fields to be populated in email

**URL:** https://discuss.elastic.co/t/watcher-payload-fields-to-be-populated-in-email/184920
**Category:** Kibana
**Tags:** elastic-stack-alerting
**Created:** [June 10, 2019, 5:57am UTC](https://discuss.elastic.co/t/watcher-payload-fields-to-be-populated-in-email/184920 "2019-06-10T05:57:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![chintan.rami](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@chintan.rami](https://discuss.elastic.co/u/chintan.rami)
#### Post date: [June 10, 2019, 5:57am UTC](https://discuss.elastic.co/t/watcher-payload-fields-to-be-populated-in-email/184920/1 "2019-06-10T05:57:45Z")

</div>

Follwoing is what I am trying to display in email  
###########################  
Queue: $DstIn$ --\> value: 86.0  
Queue: FAG --\> value: 30.0  
############################  
I have tried following however no luck.  
Queue: {{#ctx.payload.aggregations.bucketAgg.buckets.0}}{{key}}{{/ctx.payload.aggregations.bucketAgg.buckets.0}} --\> Value: {{#ctx.payload.aggregations.bucketAgg.buckets.0.metricAgg}}{{value}}{{/ctx.payload.aggregations.bucketAgg.buckets.0.metricAgg}}

Tying to list all top 5 results, any help on this would be highly appreciated.  
Here is the POST result of watcher API  
{  
"\_id" : "d1e82dfd-26ec-41ab-b0a0-47b9dab2430d\_65edf162-8394-45ee-bed4-96bd38a5c625-2019-06-10T06:25:05.492Z",  
"watch\_record" : {  
"watch\_id" : "d1e82dfd-26ec-41ab-b0a0-47b9dab2430d",  
"node" : "ZE2G-NvmQ72d5b\_08LVueQ",  
"state" : "execution\_not\_needed",  
"user" : "ramic",  
"status" : {  
"state" : {  
"active" : true,  
"timestamp" : "2019-06-10T05:59:22.563Z"  
},  
"last\_checked" : "2019-06-10T06:25:05.492Z",  
"actions" : {  
"email\_1" : {  
"ack" : {  
"timestamp" : "2019-06-10T05:59:22.563Z",  
"state" : "awaits\_successful\_execution"  
}  
}  
},  
"execution\_state" : "execution\_not\_needed",  
"version" : 144  
},  
"trigger\_event" : {  
"type" : "manual",  
"triggered\_time" : "2019-06-10T06:25:05.492Z",  
"manual" : {  
"schedule" : {  
"scheduled\_time" : "2019-06-10T06:25:05.492Z"  
}  
}  
},  
"input" : {  
"search" : {  
"request" : {  
"search\_type" : "query\_then\_fetch",  
"indices" : [  
"cougar-qlog-host-_"  
],  
"rest\_total\_hits\_as\_int" : true,  
"body" : {  
"size" : 0,  
"query" : {  
"bool" : {  
"filter" : {  
"range" : {  
"@timestamp" : {  
"gte" : "{{ctx.trigger.scheduled\_time}}||-5m",  
"lte" : "{{ctx.trigger.scheduled\_time}}",  
"format" : "strict\_date\_optional\_time||epoch\_millis"  
}  
}  
}  
}  
},  
"aggs" : {  
"bucketAgg" : {  
"terms" : {  
"field" : "queue.keyword",  
"size" : 5,  
"order" : {  
"metricAgg" : "desc"  
}  
},  
"aggs" : {  
"metricAgg" : {  
"max" : {  
"field" : "all\_current"  
}  
}  
}  
}  
}  
}  
}  
}  
},  
"condition" : {  
"script" : {  
"source" : "ArrayList arr = ctx.payload.aggregations.bucketAgg.buckets; for (int i = 0; i \< arr.length; i++) { if (arr[i]['metricAgg'].value \> params.threshold) { return true; } } return false;",  
"lang" : "painless",  
"params" : {  
"threshold" : 50000  
}  
}  
},  
"metadata" : {  
"name" : "Test",  
"watcherui" : {  
"trigger\_interval\_unit" : "m",  
"agg\_type" : "max",  
"time\_field" : "@timestamp",  
"trigger\_interval\_size" : 1,  
"term\_size" : 5,  
"time\_window\_unit" : "m",  
"threshold\_comparator" : "\>",  
"term\_field" : "queue.keyword",  
"index" : [  
"cougar-qlog-host-_"  
],  
"time\_window\_size" : 5,  
"threshold" : 50000,  
"agg\_field" : "all\_current"  
},  
"xpack" : {  
"type" : "threshold"  
}  
},  
"result" : {  
"execution\_time" : "2019-06-10T06:25:05.492Z",  
"execution\_duration" : 16,  
"input" : {  
"type" : "search",  
"status" : "success",  
"payload" : {  
"\_shards" : {  
"total" : 75,  
"failed" : 0,  
"successful" : 75,  
"skipped" : 0  
},  
"hits" : {  
"hits" : ,  
"total" : 1557,  
"max\_score" : null  
},  
"took" : 16,  
"timed\_out" : false,  
"aggregations" : {  
"bucketAgg" : {  
"doc\_count\_error\_upper\_bound" : -1,  
"sum\_other\_doc\_count" : 1312,  
"buckets" : [  
{  
"doc\_count" : 15,  
"metricAgg" : {  
"value" : 552.0  
},  
"key" : "000004D3"  
},  
{  
"doc\_count" : 25,  
"metricAgg" : {  
"value" : 197.0  
},  
"key" : "DstIn"  
},  
{  
"doc\_count" : 25,  
"metricAgg" : {  
"value" : 62.0  
},  
"key" : "000003F3"  
},  
{  
"doc\_count" : 24,  
"metricAgg" : {  
"value" : 60.0  
},  
"key" : "BridgeNV"  
},  
{  
"doc\_count" : 6,  
"metricAgg" : {  
"value" : 55.0  
},  
"key" : "SAT"  
}  
]  
}  
}  
},  
"search" : {  
"request" : {  
"search\_type" : "query\_then\_fetch",  
"indices" : [  
"cougar-qlog-host-\*"  
],  
"rest\_total\_hits\_as\_int" : true,  
"body" : {  
"size" : 0,  
"query" : {  
"bool" : {  
"filter" : {  
"range" : {  
"@timestamp" : {  
"gte" : "2019-06-10T06:25:05.492Z||-5m",  
"lte" : "2019-06-10T06:25:05.492Z",  
"format" : "strict\_date\_optional\_time||epoch\_millis"  
}  
}  
}  
}  
},  
"aggs" : {  
"bucketAgg" : {  
"terms" : {  
"field" : "queue.keyword",  
"size" : 5,  
"order" : {  
"metricAgg" : "desc"  
}  
},  
"aggs" : {  
"metricAgg" : {  
"max" : {  
"field" : "all\_current"  
}  
}  
}  
}  
}  
}  
}  
}  
},  
"condition" : {  
"type" : "script",  
"status" : "success",  
"met" : false  
},  
"actions" :   
},  
"messages" :   
}  
}

---

<div class="post-metadata">

### Author: ![chintan.rami](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@chintan.rami](https://discuss.elastic.co/u/chintan.rami)
#### Post date: [June 11, 2019, 1:59am UTC](https://discuss.elastic.co/t/watcher-payload-fields-to-be-populated-in-email/184920/3 "2019-06-11T01:59:39Z")

</div>

Was able to get the results by simply using the {{ctx.payload}} and its results displayed all 5 results that I was looking for.

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [June 11, 2019, 2:08am UTC](https://discuss.elastic.co/t/watcher-payload-fields-to-be-populated-in-email/184920/4 "2019-06-11T02:08:24Z")

</div>

Welcome, and thanks for sharing your solution! 😃

Just as a future suggestion, please format your code/logs/config using the `</>` button, or markdown style back ticks. It helps to make things easy to read which helps us help you 🙂

---

<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 9, 2019, 2:08am UTC](https://discuss.elastic.co/t/watcher-payload-fields-to-be-populated-in-email/184920/5 "2019-07-09T02:08:33Z")

</div>

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