OpenSearch/docs/reference/query-dsl/parent-id-query.asciidoc
Adrien Grand 1b660821a2
Allow _doc as a type. (#27816)
Allowing `_doc` as a type will enable users to make the transition to 7.0
smoother since the index APIs will be `PUT index/_doc/id` and `POST index/_doc`.
This also moves most of the documentation to `_doc` as a type name.

Closes #27750
Closes #27751
2017-12-14 17:47:53 +01:00

71 lines
1.5 KiB
Plaintext

[[query-dsl-parent-id-query]]
=== Parent Id Query
The `parent_id` query can be used to find child documents which belong to a particular parent.
Given the following mapping definition:
[source,js]
--------------------------------------------
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"
}
}
--------------------------------------------
// CONSOLE
// TESTSETUP
[source,js]
--------------------------------------------------
GET /my_index/_search
{
"query": {
"parent_id": {
"type": "my_child",
"id": "1"
}
}
}
--------------------------------------------------
// CONSOLE
==== Parameters
This query has two required parameters:
[horizontal]
`type`:: The **child** type name, as specified in the <<parent-join,`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.