Skip to content

Commit de9b91f

Browse files
authored
Add a reference on returning fields during a search. (#57500)
This PR adds a section to the new 'run a search' reference that explains the options for returning fields. Previously each option was only listed as a separate request parameter and it was hard to know what was available.
1 parent 29b5643 commit de9b91f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/reference/search/run-a-search.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,5 @@ GET /*/_search
285285
====
286286

287287
include::request/from-size.asciidoc[]
288+
289+
include::search-fields.asciidoc[]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[discrete]
2+
[[search-fields]]
3+
=== Return fields in a search
4+
5+
By default, each hit in the search response includes the document
6+
<<mapping-source-field,`_source`>>, which is the entire JSON object that was
7+
provided when indexing the document. If you only need certain fields in the
8+
search response, you can use
9+
<<request-body-search-source-filtering,source filtering>> to restrict what
10+
parts of the source are returned.
11+
12+
Returning fields using only the document source has some limitations:
13+
14+
* The `_source` field does not include <<multi-fields, multi-fields>> or
15+
<<alias, field aliases>>. Likewise, a field in the source does not contain
16+
values copied using the <<copy-to,`copy_to`>> mapping parameter.
17+
* Since the `_source` is stored as a single field in Lucene, the whole source
18+
object must be loaded and parsed, even if only a small number of fields are
19+
needed.
20+
21+
{es} supports some alternative methods for returning fields that help avoid
22+
these downsides:
23+
24+
* The <<request-body-search-docvalue-fields, `docvalue_fields`>>
25+
parameter allows for loading fields from their doc values. This can be a good
26+
choice when returning a fairly small number of fields that support doc values,
27+
such as keywords and dates.
28+
* It's also possible to store an individual field's values by using the
29+
<<mapping-store,`store`>> mapping option. You can use the
30+
<<request-body-search-stored-fields, `stored_fields`>> parameter to return
31+
these stored values in the search response.

0 commit comments

Comments
 (0)