# Parent aggregation based on child terms

**URL:** <https://discuss.elastic.co/t/parent-aggregation-based-on-child-terms/86826>\
**Category:** Elasticsearch\
**Created:** [May 23, 2017, 2:29pm UTC](https://discuss.elastic.co/t/parent-aggregation-based-on-child-terms/86826 "2017-05-23T14:29:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soumitra](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@Soumitra](https://discuss.elastic.co/u/Soumitra)\
**Post date:** [May 23, 2017, 2:29pm UTC](https://discuss.elastic.co/t/parent-aggregation-based-on-child-terms/86826/1 "2017-05-23T14:29:13Z")

</div>

Hello,

I have following parent child mapping ([https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child-mapping.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child-mapping.html)).

```
PUT /site
{
    "mappings": {
        "blog": {
            "properties" : { "visited": { "type": "long" }
            },
            "comment": {
                "_parent": {
                    "type": "blog",
                    "properties" : { "tag": { "type": "string" } }
                }
            }
        }
    }
}

```

I want to sum "visited" in parent document "blog" for every unique values of "tag" in child document "comment".

```
{
    "size": 0,
        "query": {
            { "match_all" : { } }
        },
        "aggs": {
            "by_tags": {
                "children": {
                    "type": "comment"
                },
                "terms": { "field": "tag" }
                "aggs": {
                    "visited": { "sum": { "field": "visited" } }
                }
            }
        }
}

```

It is not working. Am I doing something wrong, or it is not possible?

Thanks,  
-Soumitra.

---

<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:** [June 20, 2017, 2:29pm UTC](https://discuss.elastic.co/t/parent-aggregation-based-on-child-terms/86826/2 "2017-06-20T14:29:17Z")

</div>

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