|
| 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