Parent Id Query

edit

The parent_id query can be used to find child documents which belong to a particular parent. Given the following mapping definition:

PUT my_index
{
  "mappings": {
    "doc": {
      "properties": {
        "my_join_field": {
          "type": "join",
          "relations": {
            "my_parent": "my_child"
          }
        }
      }
    }
  }
}

PUT my_index/doc/1?refresh
{
  "text": "This is a parent document",
  "my_join_field": "my_parent"
}

PUT my_index/doc/2?routing=1&refresh
{
  "text": "This is a child document",
  "my_join_field": {
    "name": "my_child",
    "parent": "1"
  }
}
GET /my_index/_search
{
  "query": {
    "parent_id": {
      "type": "my_child",
      "id": "1"
    }
  }
}

Parameters

edit

This query has two required parameters:

type

The child type name, as specified in the join field.

id

The ID of the parent document.

ignore_unmapped

When set to true this will ignore an unmapped type and will not match any documents for this query. This can be useful when querying multiple indexes which might have different mappings. When set to false (the default value) the query will throw an exception if the type is not mapped.