Skip to content

Commit 40c6980

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 207704d commit 40c6980

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

docs/reference/mapping/types/nested.asciidoc

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

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

165181
[[nested-params]]
166182
==== Parameters for `nested` fields
@@ -180,21 +196,6 @@ The following parameters are accepted by `nested` fields:
180196
may be added to an existing nested object.
181197

182198

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ Elasticsearch to use the mappings to figure out a default format.
6868
NOTE: The default is currently to return the same output as
6969
<<search-request-script-fields,script fields>>. However it will change in 7.0
7070
to behave as if the `use_field_mapping` format was provided.
71+
72+
NOTE: On its own, `docvalue_fields` cannot be used to load fields in nested
73+
objects -- if a field contains a nested object in its path, then no data will
74+
be returned for that docvalue field. To access nested fields, `docvalue_fields`
75+
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)