Parent Aggregation Doc Count At Child Level

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

1 Like

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