# Why does elasticsearch terms bucket size effects the doc\_count of inner reverse\_nested aggregations?

**URL:** <https://discuss.elastic.co/t/why-does-elasticsearch-terms-bucket-size-effects-the-doc-count-of-inner-reverse-nested-aggregations/158937>\
**Category:** Elasticsearch\
**Created:** [November 30, 2018, 4:11pm UTC](https://discuss.elastic.co/t/why-does-elasticsearch-terms-bucket-size-effects-the-doc-count-of-inner-reverse-nested-aggregations/158937 "2018-11-30T16:11:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GrandBoonino](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grandboonino/32/55207_2.png) [@GrandBoonino](https://discuss.elastic.co/u/GrandBoonino)\
**Post date:** [November 30, 2018, 4:11pm UTC](https://discuss.elastic.co/t/why-does-elasticsearch-terms-bucket-size-effects-the-doc-count-of-inner-reverse-nested-aggregations/158937/1 "2018-11-30T16:11:51Z")

</div>

I've been trying to track down missing doc counts from a reverse nested aggregation.

My query

```auto
"aggs": {
    "mainGrouping": {
      "nested": {
        "path": "parent.child"
      },
      "aggs": {
        "uniqueCount": {
          "cardinality": {
            "field": "parent.child.id"
          }
        },
        "groupBy": {
          "terms": {
            "field": "parent.child.id",
            "size": 20, <- If I change this, my doc count for noOfParents changes
            "order": [
              {
                "noOfParents": "desc"
              }
            ]
          },
          "aggs": {
            "noOfParents": {
              "reverse_nested": {}
            }
          }
        }
      }
    }

```

So I was running it at `size:20` . I had one bucket that returned noOfParents of 7 when I know there should be 9 matches. I noticed by accident if I change the size of the terms aggregation to 50 the noOfParents was correctly showing 9 for this bucket.

Why would the size of the terms aggregation affect the doc\_count of a reverse aggregation? Is this expected behaviour or a bug? I'm using elasticsearch 5.6.

---

<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 28, 2018, 4:21pm UTC](https://discuss.elastic.co/t/why-does-elasticsearch-terms-bucket-size-effects-the-doc-count-of-inner-reverse-nested-aggregations/158937/2 "2018-12-28T16:21:21Z")

</div>

Closed on December 28, 2018, 4:21pm UTC

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