# Parent Aggregation Doc Count At Child Level

**URL:** <https://discuss.elastic.co/t/parent-aggregation-doc-count-at-child-level/206441>\
**Category:** Elasticsearch\
**Created:** [November 4, 2019, 4:41pm UTC](https://discuss.elastic.co/t/parent-aggregation-doc-count-at-child-level/206441 "2019-11-04T16:41:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Cross1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_cross1/32/47236_2.png) [@Justin\_Cross1](https://discuss.elastic.co/u/Justin_Cross1)\
**Post date:** [November 4, 2019, 4:41pm UTC](https://discuss.elastic.co/t/parent-aggregation-doc-count-at-child-level/206441/1 "2019-11-04T16:41:50Z")

</div>

I am using parent-child mapping and have a query using has\_parent where I search on parent fields and it returns the children. Then in there I also have a filter on the child fields as well. That is working good.

But now I am doing aggregations, and I am using parent aggregation but I want the doc count to be at a child level.  
Like let's say I get back 100 children, I want the sum of each parent\_field1 aggregation doc\_count combined to equal 100. Like if I have 2 buckets in parent\_field1 I expect the doc\_count's to add up to 100 but they might only add up to 20 (meaning 20 parents exist for the 100 children). Anyway for me to get it to count the doc\_count from the children instead of parents?

```
"aggs": {
    "child_field.keyword": {
        "terms": {
            "field": "child_field.keyword"
        }
    },
    "parent-agg": {
        "parent": {
            "type": "child"
        },
        "aggs": {
            "parent_field1.keyword": {
                "terms": {
                    "field": "parent_field1.keyword"
                }
            },
            "parent_field2.keyword": {
                "terms": {
                    "field": "parent_field2.keyword"
                }
            }
        }
    }
}

```

Thanks,  
Justin Cross

---

<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 2, 2019, 4:41pm UTC](https://discuss.elastic.co/t/parent-aggregation-doc-count-at-child-level/206441/2 "2019-12-02T16:41:54Z")

</div>

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