|
@@ -3,32 +3,60 @@
|
|
|
|
|
|
added[5.0.0]
|
|
|
|
|
|
-The `parent_id` query can be used to find child documents which belong to a particular parent:
|
|
|
+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
|
|
|
{
|
|
|
- "parent_id" : {
|
|
|
- "type" : "blog_tag",
|
|
|
- "id" : "1"
|
|
|
+ "mappings": {
|
|
|
+ "blog_post": {
|
|
|
+ "properties": {
|
|
|
+ "name": {
|
|
|
+ "type": "keyword"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "blog_tag": {
|
|
|
+ "_parent": {
|
|
|
+ "type": "blog_post"
|
|
|
+ },
|
|
|
+ "_routing": {
|
|
|
+ "required": true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
// CONSOLE
|
|
|
// TESTSETUP
|
|
|
|
|
|
+[source,js]
|
|
|
+--------------------------------------------------
|
|
|
+GET /_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 /_search
|
|
|
+GET /my_index/_search
|
|
|
{
|
|
|
"query": {
|
|
|
"has_parent": {
|
|
|
- "type": "blog",
|
|
|
+ "type": "blog_post",
|
|
|
"query": {
|
|
|
"term": {
|
|
|
"_id": "1"
|