# Comparing the last aggregated sub bucket count in the watcher condition

**URL:** <https://discuss.elastic.co/t/comparing-the-last-aggregated-sub-bucket-count-in-the-watcher-condition/276950>\
**Category:** Kibana\
**Tags:** elastic-stack-alerting\
**Created:** [June 24, 2021, 2:58pm UTC](https://discuss.elastic.co/t/comparing-the-last-aggregated-sub-bucket-count-in-the-watcher-condition/276950 "2021-06-24T14:58:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkatkumar229](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatkumar229/32/104663_2.png) [@venkatkumar229](https://discuss.elastic.co/u/venkatkumar229)\
**Post date:** [June 24, 2021, 2:58pm UTC](https://discuss.elastic.co/t/comparing-the-last-aggregated-sub-bucket-count-in-the-watcher-condition/276950/1 "2021-06-24T14:58:54Z")

</div>

Hi Team,

I am working on a watcher alert which will send an alert when the last aggregated bucket doc\_count crossed certain value. Could you please help me how to achieve it to compare the last sub backets doc\_count value. I have used array\_compare in the wacther condition as below.

My aggregation:  
"aggs": {  
"dc\_aggs": {  
"terms": {  
"field": "dc"  
},  
"aggs": {  
"rule\_aggs": {  
"terms": {  
"field": "rule"  
},  
"aggs": {  
"alertid\_aggs": {  
"terms": {  
"field": "alertid"  
},  
"aggs": {  
"primary\_page\_aggs": {  
"terms": {  
"field": "primary\_page"  
},  
"aggs": {  
"activity\_aggs": {  
"terms": {  
"field": "activity"  
},  
"aggs": {  
"last\_input\_aggs": {  
"terms": {  
"field": "last\_input"  
},  
"aggs": {  
"last\_step": {  
"terms": {  
"field": "last\_step"  
},  
"aggs": {  
"stack\_aggs": {  
"terms": {  
"field": "stack"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

I want to compare the count of last sub bucket "stack\_aggs" doc\_count \> some value. is it possible. I have tried like below but it is not working. Please help me how can i do it.

"condition": {  
"array\_compare": {  
"ctx.payload.aggregations.dc\_aggs.buckets.rule\_aggs.buckets.alertid\_aggs.buckets.primary\_page\_aggs.buckets.activity\_aggs.buckets.last\_input\_aggs.buckets.last\_step.buckets.stack\_aggs.buckets": {  
"path": "doc\_count",  
"gt": {  
"value": 170,  
"quantifier": "some"  
}  
}  
}  
}

---

<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:** [June 29, 2021, 9:08am UTC](https://discuss.elastic.co/t/comparing-the-last-aggregated-sub-bucket-count-in-the-watcher-condition/276950/2 "2021-06-29T09:08:24Z")

</div>

Please take the time to properly format your messages. This forums supports markdown and code snippets, which improves your readability a lot.

Also, can you share the response to figure out the right path?

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:** [July 27, 2021, 9:08am UTC](https://discuss.elastic.co/t/comparing-the-last-aggregated-sub-bucket-count-in-the-watcher-condition/276950/3 "2021-07-27T09:08:27Z")

</div>

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