# How to define document count for metricAgg

**URL:** <https://discuss.elastic.co/t/how-to-define-document-count-for-metricagg/159102>\
**Category:** Elasticsearch\
**Created:** [December 3, 2018, 7:16am UTC](https://discuss.elastic.co/t/how-to-define-document-count-for-metricagg/159102 "2018-12-03T07:16:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gayathri](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gayathri](https://discuss.elastic.co/u/gayathri)\
**Post date:** [December 3, 2018, 7:16am UTC](https://discuss.elastic.co/t/how-to-define-document-count-for-metricagg/159102/1 "2018-12-03T07:16:44Z")

</div>

Hi Team,

Kindly let me know how redefine the size of documents for avg calculation while using metricAgg in Watcher query.

tried the below, still it is counting for only 10 documents:

"aggs": {  
"bucketAgg": {  
"terms": {  
"field": "message.keyword",  
"size": 20,  
"order": {  
"metricAgg": "desc"  
}  
},  
"aggs": {  
"metricAgg": {  
"avg": {  
"field": "Time"  
}  
}  
}  
}  
}

Please find below the full watch:

{  
"trigger": {  
"schedule": {  
"interval": "30s"  
}  
},  
"input": {  
"search": {  
"request": {  
"search\_type": "query\_then\_fetch",  
"indices": [  
"index\*"  
],  
"types": ,  
"body": {  
"query": {  
"bool": {  
"filter": {  
"range": {  
"@timestamp": {  
"from": "now-30s",  
"to": "now"  
}  
}  
}  
}  
},  
"aggs": {  
"bucketAgg": {  
"terms": {  
"field": "message.keyword",  
"size": 20,  
"order": {  
"metricAgg": "desc"  
}  
},  
"aggs": {  
"metricAgg": {  
"avg": {  
"field": "Time"  
}  
}  
}  
}  
}  
}  
}  
}  
},  
"condition": {  
"script": {  
"source": "if (ctx.payload.aggregations.metricAgg.value \> params.threshold) { return true; } return false;",  
"lang": "painless",  
"params": {  
"threshold": 1000  
}  
}  
},  
"actions": {  
"email\_admin": {  
"throttle\_period":"30s",  
"email": {  
"profile": "standard",  
"to": [  
"[name.mail.com](http://name.mail.com)"  
],  
"subject": "ALERTS",  
"body": {  
"text": " WATCHER - Time exceeded 1000 "  
}  
}  
}  
}  
}

---

<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:** [December 31, 2018, 7:16am UTC](https://discuss.elastic.co/t/how-to-define-document-count-for-metricagg/159102/2 "2018-12-31T07:16:52Z")

</div>

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