2019-07-17 08:49:22 -04:00
[[request-body-search-stored-fields]]
2019-07-19 14:35:36 -04:00
==== Stored Fields
2013-08-28 19:24:34 -04:00
2016-06-21 05:27:27 -04:00
WARNING: The `stored_fields` parameter is about fields that are explicitly marked as
2015-11-03 05:18:00 -05:00
stored in the mapping, which is off by default and generally not recommended.
2019-07-19 09:16:35 -04:00
Use <<request-body-search-source-filtering,source filtering>> instead to select
2015-11-03 05:18:00 -05:00
subsets of the original source document to be returned.
2013-11-13 10:53:10 -05:00
Allows to selectively load specific stored fields for each document represented
by a search hit.
2013-08-28 19:24:34 -04:00
[source,js]
--------------------------------------------------
2016-05-18 07:15:19 -04:00
GET /_search
2013-08-28 19:24:34 -04:00
{
2016-06-21 05:27:27 -04:00
"stored_fields" : ["user", "postDate"],
2013-08-28 19:24:34 -04:00
"query" : {
"term" : { "user" : "kimchy" }
}
}
--------------------------------------------------
2016-05-18 07:15:19 -04:00
// CONSOLE
2013-08-28 19:24:34 -04: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:
[source,js]
--------------------------------------------------
2016-05-18 07:15:19 -04:00
GET /_search
2013-08-28 19:24:34 -04:00
{
2016-06-21 05:27:27 -04:00
"stored_fields" : [],
2013-08-28 19:24:34 -04:00
"query" : {
"term" : { "user" : "kimchy" }
}
}
--------------------------------------------------
2016-05-18 07:15:19 -04:00
// CONSOLE
2013-08-28 19:24:34 -04:00
2016-09-13 14:54:41 -04:00
If the requested fields are not stored (`store` mapping set to `false`), they will be ignored.
2013-11-13 10:53:10 -05:00
2017-07-05 06:30:19 -04: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 17:38:08 -05:00
Also only leaf fields can be returned via the `field` option. So object fields can't be returned and such requests
will fail.
2013-08-28 19:24:34 -04:00
Script fields can also be automatically detected and used as fields, so
2014-01-02 17:38:08 -05:00
things like `_source.obj1.field1` can be used, though not recommended, as
`obj1.field1` will work as well.
2013-08-28 19:24:34 -04:00
2019-05-31 11:53:59 -04: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`
2019-07-19 09:16:35 -04:00
must be used within an <<request-body-search-inner-hits, `inner_hits`>> block.
2019-05-31 11:53:59 -04:00
2019-07-19 14:35:36 -04:00
===== Disable stored fields entirely
2016-08-17 09:59:38 -04:00
2017-02-03 04:18:01 -05:00
To disable the stored fields (and metadata fields) entirely use: `_none_`:
2016-08-17 09:59:38 -04:00
[source,js]
--------------------------------------------------
GET /_search
{
"stored_fields": "_none_",
"query" : {
"term" : { "user" : "kimchy" }
}
}
--------------------------------------------------
// CONSOLE
2019-07-19 09:16:35 -04:00
NOTE: <<request-body-search-source-filtering,`_source`>> and <<request-body-search-version, `version`>> parameters cannot be activated if `_none_` is used.
2016-08-17 09:59:38 -04:00