Skip to content

Commit b555f2b

Browse files
committed
Clarify that inner_hits must be used to access nested fields. (#42724)
This PR updates the docs for `docvalue_fields` and `stored_fields` to clarify that nested fields must be accessed through `inner_hits`. It also tweaks the nested fields documentation to make this point more visible. Addresses #23766.
1 parent 7210020 commit b555f2b

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

docs/reference/mapping/types/nested.asciidoc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,22 @@ Nested documents can be:
159159
* sorted with <<nested-sorting,nested sorting>>.
160160
* retrieved and highlighted with <<nested-inner-hits,nested inner hits>>.
161161

162+
[IMPORTANT]
163+
=============================================
164+
165+
Because nested documents are indexed as separate documents, they can only be
166+
accessed within the scope of the `nested` query, the
167+
`nested`/`reverse_nested` aggregations, or <<nested-inner-hits,nested inner hits>>.
168+
169+
For instance, if a string field within a nested document has
170+
<<index-options,`index_options`>> set to `offsets` to allow use of the postings
171+
during the highlighting, these offsets will not be available during the main highlighting
172+
phase. Instead, highlighting needs to be performed via
173+
<<nested-inner-hits,nested inner hits>>. The same consideration applies when loading
174+
fields during a search through <<search-request-docvalue-fields, `docvalue_fields`>>
175+
or <<search-request-stored-fields, `stored_fields`>>.
176+
177+
=============================================
162178

163179
[[nested-params]]
164180
==== Parameters for `nested` fields
@@ -178,21 +194,6 @@ The following parameters are accepted by `nested` fields:
178194
may be added to an existing nested object.
179195

180196

181-
[IMPORTANT]
182-
=============================================
183-
184-
Because nested documents are indexed as separate documents, they can only be
185-
accessed within the scope of the `nested` query, the
186-
`nested`/`reverse_nested` aggregations, or <<nested-inner-hits,nested inner hits>>.
187-
188-
For instance, if a string field within a nested document has
189-
<<index-options,`index_options`>> set to `offsets` to allow use of the postings
190-
during the highlighting, these offsets will not be available during the main highlighting
191-
phase. Instead, highlighting needs to be performed via
192-
<<nested-inner-hits,nested inner hits>>.
193-
194-
=============================================
195-
196197
[float]
197198
=== Limits on `nested` mappings and objects
198199

docs/reference/search/request/docvalue-fields.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ on their mappings: `long`, `double` and other numeric fields are formatted as
6767
numbers, `keyword` fields are formatted as strings, `date` fields are formatted
6868
with the configured `date` format, etc.
6969

70+
NOTE: On its own, `docvalue_fields` cannot be used to load fields in nested
71+
objects -- if a field contains a nested object in its path, then no data will
72+
be returned for that docvalue field. To access nested fields, `docvalue_fields`
73+
must be used within an <<search-request-inner-hits, `inner_hits`>> block.

docs/reference/search/request/stored-fields.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ Script fields can also be automatically detected and used as fields, so
4949
things like `_source.obj1.field1` can be used, though not recommended, as
5050
`obj1.field1` will work as well.
5151

52+
NOTE: On its own, `stored_fields` cannot be used to load fields in nested
53+
objects -- if a field contains a nested object in its path, then no data will
54+
be returned for that stored field. To access nested fields, `stored_fields`
55+
must be used within an <<search-request-inner-hits, `inner_hits`>> block.
56+
5257
==== Disable stored fields entirely
5358

5459
To disable the stored fields (and metadata fields) entirely use: `_none_`:

0 commit comments

Comments
 (0)