# Problem with parent-child join

**URL:** <https://discuss.elastic.co/t/problem-with-parent-child-join/270278>\
**Category:** Elasticsearch\
**Created:** [April 15, 2021, 3:46pm UTC](https://discuss.elastic.co/t/problem-with-parent-child-join/270278 "2021-04-15T15:46:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarlMan](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@MarlMan](https://discuss.elastic.co/u/MarlMan)\
**Post date:** [April 15, 2021, 3:46pm UTC](https://discuss.elastic.co/t/problem-with-parent-child-join/270278/1 "2021-04-15T15:46:30Z")

</div>

Hey guys.

I have a big data set with many parents and children. My goal is to find out, how many Jo-children each parent has. So I only want to know about children which have Jo as a part of their name (Joel, John, Johnson, Jacques-Joel).

Unfortunately I have some problems:

1. When I use "match": {"name": "Jo"} as the only statement in the query it works. If try to use it with the "has\_parent" ..... it fails. Where is the right place to put this statement?
2. I would like to have the sum of Jo-children for each parent. Perfect would be sum of names for all children of each parent. Currently I'm only able to add the ages of all children. Is there a way to count the number of text fields (as an example "names")?
3. Is it possible to aggregate in a single statement for each parent or do I have to write for every parent a separate statement?

If anyone has an answer to one of these problems I would be really grateful.

My current request:

```
GET /testproject/_search

{
  "size": 1,
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": "Jo"
          }, 
          "has_parent": {
            "parent_type": "parent",
            "query": {
              "match_all": {}
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "amount_posts": {
      "sum": {
        "field": "age"
      }
    }
  }
}
```

---

<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:** [May 13, 2021, 3:46pm UTC](https://discuss.elastic.co/t/problem-with-parent-child-join/270278/2 "2021-05-13T15:46:47Z")

</div>

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