2020-08-06 13:06:06 -04:00
WARNING: The `stored_fields` parameter is for fields that are explicitly marked as
2015-11-03 11:18:00 +01:00
stored in the mapping, which is off by default and generally not recommended.
2020-06-11 11:25:04 -04:00
Use <<source-filtering,source filtering>> instead to select
2015-11-03 11:18:00 +01:00
subsets of the original source document to be returned.
2013-11-13 16:53:10 +01:00
Allows to selectively load specific stored fields for each document represented
by a search hit.
2013-08-29 01:24:34 +02:00
2019-09-09 12:35:50 -04:00
[source,console]
2013-08-29 01:24:34 +02:00
--------------------------------------------------
2016-05-18 13:15:19 +02:00
GET /_search
2013-08-29 01:24:34 +02:00
{
2020-07-21 15:49:58 -04:00
"stored_fields" : ["user", "postDate"],
"query" : {
"term" : { "user" : "kimchy" }
}
2013-08-29 01:24:34 +02:00
}
--------------------------------------------------
`*` can be used to load all stored fields from the document.
An empty array will cause only the `_id` and `_type` for each hit to be
returned, for example:
2019-09-09 12:35:50 -04:00
[source,console]
2013-08-29 01:24:34 +02:00
--------------------------------------------------
2016-05-18 13:15:19 +02:00
GET /_search
2013-08-29 01:24:34 +02:00
{
2020-07-21 15:49:58 -04:00
"stored_fields" : [],
"query" : {
"term" : { "user" : "kimchy" }
}
2013-08-29 01:24:34 +02:00
}
--------------------------------------------------
2016-09-13 20:54:41 +02:00
If the requested fields are not stored (`store` mapping set to `false`), they will be ignored.
2013-11-13 16:53:10 +01:00
2017-07-05 12:30:19 +02:00
Stored field values fetched from the document itself are always returned as an array. On the contrary, metadata fields like `_routing` are never returned as an array.
2014-01-02 23:38:08 +01:00
2020-03-09 10:57:23 -07:00
Also only leaf fields can be returned via the `stored_fields` option. If an object field is specified, it will be ignored.
2013-08-29 01:24:34 +02:00
2019-05-31 08:53:59 -07:00
NOTE: On its own, `stored_fields` cannot be used to load fields in nested
objects -- if a field contains a nested object in its path, then no data will
be returned for that stored field. To access nested fields, `stored_fields`
2020-08-06 14:06:01 -04:00
must be used within an <<inner-hits, `inner_hits`>> block.
2019-05-31 08:53:59 -07:00
2020-08-06 13:06:06 -04:00
[discrete]
[[disable-stored-fields]]
==== Disable stored fields
2016-08-17 15:59:38 +02:00
2017-02-03 10:18:01 +01:00
To disable the stored fields (and metadata fields) entirely use: `_none_`:
2016-08-17 15:59:38 +02:00
2019-09-09 12:35:50 -04:00
[source,console]
2016-08-17 15:59:38 +02:00
--------------------------------------------------
GET /_search
{
2020-07-21 15:49:58 -04:00
"stored_fields": "_none_",
"query" : {
"term" : { "user" : "kimchy" }
}
2016-08-17 15:59:38 +02:00
}
--------------------------------------------------
2020-06-11 11:25:04 -04:00
NOTE: <<source-filtering,`_source`>> and <<request-body-search-version, `version`>> parameters cannot be activated if `_none_` is used.
2016-08-17 15:59:38 +02:00