67 lines
2.2 KiB
Plaintext
67 lines
2.2 KiB
Plaintext
[[request-body-search-stored-fields]]
|
|
==== Stored Fields
|
|
|
|
WARNING: The `stored_fields` parameter is about fields that are explicitly marked as
|
|
stored in the mapping, which is off by default and generally not recommended.
|
|
Use <<request-body-search-source-filtering,source filtering>> instead to select
|
|
subsets of the original source document to be returned.
|
|
|
|
Allows to selectively load specific stored fields for each document represented
|
|
by a search hit.
|
|
|
|
[source,console]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"stored_fields" : ["user", "postDate"],
|
|
"query" : {
|
|
"term" : { "user" : "kimchy" }
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
`*` 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,console]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"stored_fields" : [],
|
|
"query" : {
|
|
"term" : { "user" : "kimchy" }
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
If the requested fields are not stored (`store` mapping set to `false`), they will be ignored.
|
|
|
|
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.
|
|
|
|
Also only leaf fields can be returned via the `stored_fields` option. If an object field is specified, it will be ignored.
|
|
|
|
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`
|
|
must be used within an <<request-body-search-inner-hits, `inner_hits`>> block.
|
|
|
|
===== Disable stored fields entirely
|
|
|
|
To disable the stored fields (and metadata fields) entirely use: `_none_`:
|
|
|
|
[source,console]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"stored_fields": "_none_",
|
|
"query" : {
|
|
"term" : { "user" : "kimchy" }
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
NOTE: <<request-body-search-source-filtering,`_source`>> and <<request-body-search-version, `version`>> parameters cannot be activated if `_none_` is used.
|
|
|