Skip to content

[DOCS] Reformat parent_id query docs #44449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 82 additions & 37 deletions docs/reference/query-dsl/parent-id-query.asciidoc
Original file line number Diff line number Diff line change
@@ -1,68 +1,113 @@
[[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:
Returns child documents <<parent-join,joined>> to a specific parent document.
You can use a <<parent-join,join>> field mapping to create parent-child
relationships between documents in the same index.

[[parent-id-query-ex-request]]
==== Example request

[[parent-id-index-setup]]
===== Index setup
To use the `parent_id` query, your index must include a <<parent-join,join>>
field mapping. To see how you can set up an index for the `parent_id` query, try
the following example.

. Create an index with a <<parent-join,join>> field mapping.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. dot at the beginning of the sentence?
Here and in a couple of places below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renders as an ordered list in the HTML output. Here's a screenshot:

Screen Shot 2019-07-19 at 10 35 31 AM

+
--
[source,js]
--------------------------------------------
PUT my_index
----
PUT /my-index
{
"mappings": {
"properties": {
"my_join_field": {
"type": "join",
"relations": {
"my_parent": "my_child"
"mappings": {
"properties" : {
"my-join-field" : {
"type" : "join",
"relations": {
"my-parent": "my-child"
}
}
}
}
}
}
}

PUT my_index/_doc/1?refresh
----
// CONSOLE
// TESTSETUP
--

. Index a parent document with an ID of `1`.
+
--
[source,js]
----
PUT my-index/_doc/1?refresh
{
"text": "This is a parent document",
"my_join_field": "my_parent"
"text": "This is a parent document.",
"my-join-field": "my-parent"
}
----
// CONSOLE
--

PUT my_index/_doc/2?routing=1&refresh
. Index a child document of the parent document.
+
--
[source,js]
----
PUT my-index/_doc/2?routing=1&refresh
{
"text": "This is a child document",
"text": "This is a child document.",
"my_join_field": {
"name": "my_child",
"name": "my-child",
"parent": "1"
}
}

--------------------------------------------
----
// CONSOLE
// TESTSETUP
--

[[parent-id-query-ex-query]]
===== Example query

The following search returns child documents for a parent document with an ID of
`1`.

[source,js]
--------------------------------------------------
GET /my_index/_search
----
GET /my-index/_search
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have a unified format in all examples: either put / before index name or not? /my-index/_search -> my-index/_search

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this. I added leading slashes with 647110c.

{
"query": {
"parent_id": {
"type": "my_child",
"id": "1"
}
"parent_id": {
"type": "my-child",
"id": "1"
}
}
}
--------------------------------------------------
----
// CONSOLE

[[parent-id-top-level-params]]
==== Top-level parameters for `parent_id`

`type`::
(Required, string) Name of the child relationship mapped for the
<<parent-join,join>> field.

==== Parameters
`id`::
(Required, string) ID of the parent document. The query will return child
documents of this parent document.

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

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

`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.
You can use this parameter to query multiple indices that may not contain the
`type`.
--