2013-08-28 19:24:34 -04:00
|
|
|
[[search-request-fields]]
|
|
|
|
=== Fields
|
|
|
|
|
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]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"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" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2013-11-13 10:53:10 -05:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2014-01-02 17:38:08 -05:00
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
2013-09-25 12:17:40 -04:00
|
|
|
[[partial]]
|
2013-08-28 19:24:34 -04:00
|
|
|
==== Partial
|
|
|
|
|
2013-11-13 10:53:10 -05:00
|
|
|
deprecated[1.0.0Beta1,Replaced by <<search-request-source-filtering>>]
|
|
|
|
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
When loading data from `_source`, partial fields can be used to use
|
|
|
|
wildcards to control what part of the `_source` will be loaded based on
|
|
|
|
`include` and `exclude` patterns. For example:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"partial_fields" : {
|
|
|
|
"partial1" : {
|
|
|
|
"include" : "obj1.obj2.*",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
And one that will also exclude `obj1.obj3`:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"partial_fields" : {
|
|
|
|
"partial1" : {
|
|
|
|
"include" : "obj1.obj2.*",
|
|
|
|
"exclude" : "obj1.obj3.*"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
Both `include` and `exclude` support multiple patterns:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"partial_fields" : {
|
|
|
|
"partial1" : {
|
|
|
|
"include" : ["obj1.obj2.*", "obj1.obj4.*"],
|
|
|
|
"exclude" : "obj1.obj3.*"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|