# Min\_doc\_count on lower/lowest level nested aggregation

**URL:** <https://discuss.elastic.co/t/min-doc-count-on-lower-lowest-level-nested-aggregation/17939>\
**Category:** Elasticsearch\
**Created:** [June 5, 2014, 9:51pm UTC](https://discuss.elastic.co/t/min-doc-count-on-lower-lowest-level-nested-aggregation/17939 "2014-06-05T21:51:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Lui](https://avatars.discourse-cdn.com/v4/letter/g/3ab097/32.png) [@George\_Lui](https://discuss.elastic.co/u/George_Lui)\
**Post date:** [June 5, 2014, 9:51pm UTC](https://discuss.elastic.co/t/min-doc-count-on-lower-lowest-level-nested-aggregation/17939/1 "2014-06-05T21:51:14Z")

</div>

I have this query with some nested aggregations

_{_

- "aggs": {\*
- 

```
 "by_date": {*

```

- 

```
    "date_histogram": {*

```

- 

```
       "field": "timestamp",*

```

- 

```
       "interval": "day"*

```

- 

```
    },*

```

- 

```
    "aggs": {*

```

- 

```
       "new_users": {*

```

- 

```
          "filter": {*

```

- 

```
             "query": {*

```

- 

```
                "match": {*

```

- 

```
                   "action": "USER_ADD"*

```

- 

```
                }*

```

- 

```
             }*

```

- 

```
          },*

```

- 

```
          "aggs": {*

```

- 

```
             "unique_users": {*

```

- 

```
                "cardinality": {*

```

- 

```
                   "field": "user"*

```

- 

```
                }*

```

- 

```
             }*

```

- 

```
          }*

```

- 

```
       }*

```

- 

```
    }*

```

- 

```
 }*

```

- },\*
- "size": 0\*  
_}_

It yields results that look like this

_"aggregations": {_

- 

```
 "by_date": {*

```

- 

```
    "buckets": [*

```

- 

```
       {*

```

- 

```
          "key_as_string": "1970-01-07T00:00:00.000Z",*

```

- 

```
          "key": 518400000,*

```

- 

```
          "doc_count": 210,*

```

- 

```
          "new_users": {*

```

- 

```
             "doc_count": 0,*

```

- 

```
             "unique_users": {*

```

- 

```
                "value": 0*

```

- 

```
             }*

```

- 

```
          }*

```

- 

```
       },*

```

- 

```
       {*

```

- 

```
          "key_as_string": "1970-01-09T00:00:00.000Z",*

```

- 

```
          "key": 691200000,*

```

- 

```
          "doc_count": 6,*

```

- 

```
          "new_users": {*

```

- 

```
             "doc_count": 0,*

```

- 

```
             "unique_users": {*

```

- 

```
                "value": 0*

```

- 

```
             }*

```

- 

```
          }*

```

- 

```
       },*

```

- 

```
  ......*

```

What I want to happen is apply min\_doc\_count on the most nested  
sub-aggregation such that I don't see zero values for "unique\_users" (in  
this case) returned.

The issue is that min\_doc\_count can't be applied to my query other than the  
date\_histogram at the top level.

Does the ES query language support something like this? Any know  
workarounds?

Thanks,  
George

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/601928b2-3731-41a1-94bf-b4c039f55817%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/601928b2-3731-41a1-94bf-b4c039f55817%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:24am UTC](https://discuss.elastic.co/t/min-doc-count-on-lower-lowest-level-nested-aggregation/17939/2 "2017-07-06T01:24:23Z")

</div>


