OpenSearch/docs/reference/search/request/fields.asciidoc

52 lines
1.7 KiB
Plaintext
Raw Normal View History

[[search-request-fields]]
=== Fields
WARNING: The `fields` parameter is about fields that are explicitly marked as
stored in the mapping, which is off by default and generally not recommended.
Use <<search-request-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,js]
--------------------------------------------------
{
"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,js]
--------------------------------------------------
{
"fields" : [],
"query" : {
"term" : { "user" : "kimchy" }
}
}
--------------------------------------------------
For backwards compatibility, if the fields parameter specifies fields which are not stored (`store` mapping set to
`false`), it will load the `_source` and extract it from it. This functionality has been replaced by the
<<search-request-source-filtering,source filtering>> parameter.
Field values fetched from the document it self are always returned as an array. Metadata fields like `_routing` and
`_parent` fields are never returned as an array.
Also only leaf fields can be returned via the `field` option. So object fields can't be returned and such requests
will fail.
Script fields can also be automatically detected and used as fields, so
things like `_source.obj1.field1` can be used, though not recommended, as
`obj1.field1` will work as well.