# How to read group by buckets key values using "ctx" from below query

**URL:** <https://discuss.elastic.co/t/how-to-read-group-by-buckets-key-values-using-ctx-from-below-query/299383>\
**Category:** Elasticsearch\
**Created:** [March 11, 2022, 12:29am UTC](https://discuss.elastic.co/t/how-to-read-group-by-buckets-key-values-using-ctx-from-below-query/299383 "2022-03-11T00:29:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinivasa\_adaboina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srinivasa_adaboina/32/102904_2.png) [@srinivasa\_adaboina](https://discuss.elastic.co/u/srinivasa_adaboina)\
**Post date:** [March 11, 2022, 12:29am UTC](https://discuss.elastic.co/t/how-to-read-group-by-buckets-key-values-using-ctx-from-below-query/299383/1 "2022-03-11T00:29:43Z")

</div>

{  
"\_shards": {  
"total": 155,  
"failed": 0,  
"successful": 155,  
"skipped": 0  
},  
"hits": {  
"hits": ,  
"total": {  
"value": 5535,  
"relation": "eq"  
},  
"max\_score": null  
},  
"took": 44,  
"timed\_out": false,  
"aggregations": {  
"groupby": {  
"buckets": [  
{  
"doc\_count": 4,  
"b8d81aba": {  
"doc\_count": 4  
},  
"key": {  
"4a33222e": "msz\_client21"  
}  
},  
{  
"doc\_count": 14,  
"b8d81aba": {  
"doc\_count": 14  
},  
"key": {  
"4a33222e": "msz\_client22"  
}  
},  
{  
"doc\_count": 5,  
"b8d81aba": {  
"doc\_count": 5  
},  
"key": {  
"4a33222e": "msz\_client23"  
}  
},  
{  
"doc\_count": 5,  
"b8d81aba": {  
"doc\_count": 5  
},  
"key": {  
"4a33222e": "msz\_client24"  
}  
},  
{  
"doc\_count": 5,  
"b8d81aba": {  
"doc\_count": 5  
},  
"key": {  
"4a33222e": "msz\_client25"  
}  
},  
{  
"doc\_count": 8,  
"b8d81aba": {  
"doc\_count": 8  
},  
"key": {  
"4a33222e": "msz\_client\_staging1"  
}  
},  
{  
"doc\_count": 29,  
"b8d81aba": {  
"doc\_count": 29  
},  
"key": {  
"4a33222e": "msz\_client\_staging3"  
}  
},  
{  
"doc\_count": 11,  
"b8d81aba": {  
"doc\_count": 11  
},  
"key": {  
"4a33222e": "msz\_client\_staging5"  
}  
},  
{  
"doc\_count": 3,  
"b8d81aba": {  
"doc\_count": 3  
},  
"key": {  
"4a33222e": "msz\_client\_staging6"  
}  
},  
{  
"doc\_count": 60,  
"b8d81aba": {  
"doc\_count": 60  
},  
"key": {  
"4a33222e": "msz\_client\_staging7"  
}  
},  
{  
"doc\_count": 36,  
"b8d81aba": {  
"doc\_count": 36  
},  
"key": {  
"4a33222e": "msz\_wale"  
}  
},  
{  
"doc\_count": 96,  
"b8d81aba": {  
"doc\_count": 96  
},  
"key": {  
"4a33222e": "mszstgautousrwith"  
}  
},  
{  
"doc\_count": 16,  
"b8d81aba": {  
"doc\_count": 16  
},  
"key": {  
"4a33222e": "mszstgtest1"  
}  
},  
{  
"doc\_count": 1049,  
"b8d81aba": {  
"doc\_count": 1049  
},  
"key": {  
"4a33222e": "walestgtest1"  
}  
},  
{  
"doc\_count": 1049,  
"b8d81aba": {  
"doc\_count": 1049  
},  
"key": {  
"4a33222e": "walestgtest2"  
}  
},  
{  
"doc\_count": 1048,  
"b8d81aba": {  
"doc\_count": 1048  
},  
"key": {  
"4a33222e": "walestgtest3"  
}  
},  
{  
"doc\_count": 1048,  
"b8d81aba": {  
"doc\_count": 1048  
},  
"key": {  
"4a33222e": "walestgtest4"  
}  
},  
{  
"doc\_count": 1048,  
"b8d81aba": {  
"doc\_count": 1048  
},  
"key": {  
"4a33222e": "walestgtest5"  
}  
}  
],  
"after\_key": {  
"4a33222e": "walestgtest5"  
}  
}  
}  
}

I am reading as below but it is not working

{{ctx.payload.aggregations.groupby.buckets.key}}

---

<div class="post-metadata">

**Author:** ![casterQ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casterq/32/93257_2.png) [@casterQ](https://discuss.elastic.co/u/casterQ)\
**Post date:** [March 11, 2022, 2:51am UTC](https://discuss.elastic.co/t/how-to-read-group-by-buckets-key-values-using-ctx-from-below-query/299383/2 "2022-03-11T02:51:52Z")

</div>

`ctx` is used in `script` to access some fields，I'm not sure what you mean，use `ctx` to read response？

---

<div class="post-metadata">

**Author:** ![srinivasa\_adaboina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srinivasa_adaboina/32/102904_2.png) [@srinivasa\_adaboina](https://discuss.elastic.co/u/srinivasa_adaboina)\
**Post date:** [March 11, 2022, 4:23pm UTC](https://discuss.elastic.co/t/how-to-read-group-by-buckets-key-values-using-ctx-from-below-query/299383/3 "2022-03-11T16:23:48Z")

</div>

actually my requirement is 🙂

i am creating few alarms in kibana and i would like to show response data in email body , whenever this alert trigger , and i am trying to add response data using ctx , is there any other way to add this to email in kibana alarm trigger action ?

---

<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:** [April 8, 2022, 4:24pm UTC](https://discuss.elastic.co/t/how-to-read-group-by-buckets-key-values-using-ctx-from-below-query/299383/4 "2022-04-08T16:24:43Z")

</div>

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