Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Latest commit

 

History

History
44 lines (38 loc) · 1.54 KB

55_Has_parent.asciidoc

File metadata and controls

44 lines (38 loc) · 1.54 KB

Finding Children by Their Parents

While a nested query can always return only the root document as a result, parent and child documents are independent and each can be queried independently. The has_child query allows us to return parents based on data in their children, and the has_parent query returns children based on data in their parents.

It looks very similar to the has_child query. This example returns employees who work in the UK:

GET /company/employee/_search
{
  "query": {
    "has_parent": {
      "type": "branch", (1)
      "query": {
        "match": {
          "country": "UK"
        }
      }
    }
  }
}
  1. Returns children who have parents of type branch

The has_parent query also supports the score_mode, but it accepts only two settings: none (the default) and score. Each child can have only one parent, so there is no need to reduce multiple scores into a single score for the child. The choice is simply between using the score (score) or not (none).

Non-scoring has_parent Query

When used in non-scoring mode (e.g. inside a filter clause), the has_parent query no longer supports the score_mode parameter. Because it is merely including/excluding documents and not scoring, the score_mode parameter no longer applies.