OpenSearch/docs/reference/query-dsl/parent-id-query.asciidoc
Nik Everett 1e587406d8 Fail yaml tests and docs snippets that get unexpected warnings
Adds `warnings` syntax to the yaml test that allows you to expect
a `Warning` header that looks like:
```
    - do:
        warnings:
            - '[index] is deprecated'
            - quotes are not required because yaml
            - but this argument is always a list, never a single string
            - no matter how many warnings you expect
        get:
            index:    test
            type:    test
            id:        1
```

These are accessible from the docs with:
```
// TEST[warning:some warning]
```

This should help to force you to update the docs if you deprecate
something. You *must* add the warnings marker to the docs or the build
will fail. While you are there you *should* update the docs to add
deprecation warnings visible in the rendered results.
2016-08-04 15:23:05 -04:00

85 lines
1.9 KiB
Plaintext

[[query-dsl-parent-id-query]]
=== Parent Id Query
added[5.0.0]
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": {
"blog_post": {
"properties": {
"name": {
"type": "keyword"
}
}
},
"blog_tag": {
"_parent": {
"type": "blog_post"
},
"_routing": {
"required": true
}
}
}
}
------------------------------------------
// CONSOLE
// TESTSETUP
[source,js]
--------------------------------------------------
GET /my_index/_search
{
"query": {
"parent_id" : {
"type" : "blog_tag",
"id" : "1"
}
}
}
--------------------------------------------------
// CONSOLE
The above is functionally equivalent to using the following
<<query-dsl-has-parent-query, `has_parent`>> query, but performs
better as it does not need to do a join:
[source,js]
--------------------------------------------------
GET /my_index/_search
{
"query": {
"has_parent": {
"parent_type": "blog_post",
"query": {
"term": {
"_id": "1"
}
}
}
}
}
--------------------------------------------------
// CONSOLE
==== Parameters
This query has two required parameters:
[horizontal]
`type`:: The **child** type. This must be a type with `_parent` field.
`id`:: The required parent id select documents must referrer to.
`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.