Skip to content

Commit 1f5a2ac

Browse files
committed
[DOCS] Reformat parent_id query docs (#44449)
1 parent 804476c commit 1f5a2ac

File tree

1 file changed

+82
-37
lines changed

1 file changed

+82
-37
lines changed

docs/reference/query-dsl/parent-id-query.asciidoc

Lines changed: 82 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,113 @@
44
<titleabbrev>Parent ID</titleabbrev>
55
++++
66

7-
The `parent_id` query can be used to find child documents which belong to a particular parent.
8-
Given the following mapping definition:
7+
Returns child documents <<parent-join,joined>> to a specific parent document.
8+
You can use a <<parent-join,join>> field mapping to create parent-child
9+
relationships between documents in the same index.
910

11+
[[parent-id-query-ex-request]]
12+
==== Example request
13+
14+
[[parent-id-index-setup]]
15+
===== Index setup
16+
To use the `parent_id` query, your index must include a <<parent-join,join>>
17+
field mapping. To see how you can set up an index for the `parent_id` query, try
18+
the following example.
19+
20+
. Create an index with a <<parent-join,join>> field mapping.
21+
+
22+
--
1023
[source,js]
11-
--------------------------------------------
12-
PUT my_index
24+
----
25+
PUT /my-index
1326
{
14-
"mappings": {
15-
"properties": {
16-
"my_join_field": {
17-
"type": "join",
18-
"relations": {
19-
"my_parent": "my_child"
27+
"mappings": {
28+
"properties" : {
29+
"my-join-field" : {
30+
"type" : "join",
31+
"relations": {
32+
"my-parent": "my-child"
33+
}
34+
}
2035
}
21-
}
2236
}
23-
}
2437
}
2538
26-
PUT my_index/_doc/1?refresh
39+
----
40+
// CONSOLE
41+
// TESTSETUP
42+
--
43+
44+
. Index a parent document with an ID of `1`.
45+
+
46+
--
47+
[source,js]
48+
----
49+
PUT /my-index/_doc/1?refresh
2750
{
28-
"text": "This is a parent document",
29-
"my_join_field": "my_parent"
51+
"text": "This is a parent document.",
52+
"my-join-field": "my-parent"
3053
}
54+
----
55+
// CONSOLE
56+
--
3157

32-
PUT my_index/_doc/2?routing=1&refresh
58+
. Index a child document of the parent document.
59+
+
60+
--
61+
[source,js]
62+
----
63+
PUT /my-index/_doc/2?routing=1&refresh
3364
{
34-
"text": "This is a child document",
65+
"text": "This is a child document.",
3566
"my_join_field": {
36-
"name": "my_child",
67+
"name": "my-child",
3768
"parent": "1"
3869
}
3970
}
40-
41-
--------------------------------------------
71+
----
4272
// CONSOLE
43-
// TESTSETUP
73+
--
74+
75+
[[parent-id-query-ex-query]]
76+
===== Example query
77+
78+
The following search returns child documents for a parent document with an ID of
79+
`1`.
4480

4581
[source,js]
46-
--------------------------------------------------
47-
GET /my_index/_search
82+
----
83+
GET /my-index/_search
4884
{
4985
"query": {
50-
"parent_id": {
51-
"type": "my_child",
52-
"id": "1"
53-
}
86+
"parent_id": {
87+
"type": "my-child",
88+
"id": "1"
89+
}
5490
}
5591
}
56-
--------------------------------------------------
92+
----
5793
// CONSOLE
5894

95+
[[parent-id-top-level-params]]
96+
==== Top-level parameters for `parent_id`
97+
98+
`type`::
99+
(Required, string) Name of the child relationship mapped for the
100+
<<parent-join,join>> field.
59101

60-
==== Parameters
102+
`id`::
103+
(Required, string) ID of the parent document. The query will return child
104+
documents of this parent document.
61105

62-
This query has two required parameters:
106+
`ignore_unmapped`::
107+
+
108+
--
109+
(Optional, boolean) Indicates whether to ignore an unmapped `type` and not
110+
return any documents instead of an error. Defaults to `false`.
63111

64-
[horizontal]
65-
`type`:: The **child** type name, as specified in the <<parent-join,`join` field>>.
66-
`id`:: The ID of the parent document.
112+
If `false`, {es} returns an error if the `type` is unmapped.
67113

68-
`ignore_unmapped`:: When set to `true` this will ignore an unmapped `type` and will not match any
69-
documents for this query. This can be useful when querying multiple indexes
70-
which might have different mappings. When set to `false` (the default value)
71-
the query will throw an exception if the `type` is not mapped.
114+
You can use this parameter to query multiple indices that may not contain the
115+
`type`.
116+
--

0 commit comments

Comments
 (0)