Problem with parent-child join

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"
      }
    }
  }
}

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