# Establish minimum term count in aggregation, then do more work

**URL:** <https://discuss.elastic.co/t/establish-minimum-term-count-in-aggregation-then-do-more-work/39366>\
**Category:** Elasticsearch\
**Created:** [January 15, 2016, 11:14pm UTC](https://discuss.elastic.co/t/establish-minimum-term-count-in-aggregation-then-do-more-work/39366 "2016-01-15T23:14:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Harrison](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@Josh\_Harrison](https://discuss.elastic.co/u/Josh_Harrison)\
**Post date:** [January 15, 2016, 11:14pm UTC](https://discuss.elastic.co/t/establish-minimum-term-count-in-aggregation-then-do-more-work/39366/1 "2016-01-15T23:14:00Z")

</div>

I have a bunch of log entries in the form of {"id":"abc123", "delta":7}. I want to do a terms aggregation on id, and then get the lowest standard deviation values where the count IDs is still at least N in length.  
So if I have

> ```
> {
> "aggs": {
> "idcount": {
> "terms": {
> "field": "id",
> "order": {
> "stats.std_deviation": "asc"
> }
> },
> "aggs": {
> "stats": {
> "extended_stats": {
> "field": "delta"
> }
> }
> }
> }
> }
> }
> 
> ```

I get back the lowest standard deviation of 0, for IDs that occur only once. I want to be able to say "give me the lowest standard deviation where aggregations.idcount.doc\_count\>30, but still order by the ascending std\_deviation calculated in the nested stats agg". Any hints?

---

<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 5, 2017, 11:23pm UTC](https://discuss.elastic.co/t/establish-minimum-term-count-in-aggregation-then-do-more-work/39366/2 "2017-07-05T23:23:57Z")

</div>


