2019-07-17 08:49:22 -04:00
|
|
|
[[request-body-search-docvalue-fields]]
|
2019-07-19 14:35:36 -04:00
|
|
|
==== Doc value Fields
|
2016-06-21 05:27:27 -04:00
|
|
|
|
2016-06-23 03:44:33 -04:00
|
|
|
Allows to return the <<doc-values,doc value>> representation of a field for each hit, for
|
2016-06-21 05:27:27 -04:00
|
|
|
example:
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2016-06-21 05:27:27 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
GET /_search
|
|
|
|
{
|
|
|
|
"query" : {
|
|
|
|
"match_all": {}
|
|
|
|
},
|
2018-05-23 08:39:04 -04:00
|
|
|
"docvalue_fields" : [
|
2019-01-30 04:31:51 -05:00
|
|
|
"my_ip_field", <1>
|
2018-05-23 08:39:04 -04:00
|
|
|
{
|
2019-01-30 04:31:51 -05:00
|
|
|
"field": "my_keyword_field" <2>
|
2018-05-23 08:39:04 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"field": "my_date_field",
|
|
|
|
"format": "epoch_millis" <3>
|
|
|
|
}
|
|
|
|
]
|
2016-06-21 05:27:27 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-09 12:35:50 -04:00
|
|
|
|
2018-05-23 08:39:04 -04:00
|
|
|
<1> the name of the field
|
2019-01-30 04:31:51 -05:00
|
|
|
<2> an object notation is supported as well
|
|
|
|
<3> the object notation allows to specify a custom format
|
2016-06-21 05:27:27 -04:00
|
|
|
|
2019-01-30 04:31:51 -05:00
|
|
|
Doc value fields can work on fields that have doc-values enabled, regardless of whether they are stored
|
2016-06-21 05:27:27 -04:00
|
|
|
|
2018-08-23 04:04:00 -04:00
|
|
|
`*` can be used as a wild card, for example:
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2018-08-23 04:04:00 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
GET /_search
|
|
|
|
{
|
|
|
|
"query" : {
|
|
|
|
"match_all": {}
|
|
|
|
},
|
|
|
|
"docvalue_fields" : [
|
|
|
|
{
|
2019-01-30 04:31:51 -05:00
|
|
|
"field": "*_date_field", <1>
|
|
|
|
"format": "epoch_millis" <2>
|
2018-08-23 04:04:00 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-09 12:35:50 -04:00
|
|
|
|
2018-08-23 04:04:00 -04:00
|
|
|
<1> Match all fields ending with `field`
|
|
|
|
<2> Format to be applied to all matching fields.
|
|
|
|
|
2016-06-21 05:27:27 -04:00
|
|
|
Note that if the fields parameter specifies fields without docvalues it will try to load the value from the fielddata cache
|
|
|
|
causing the terms for that field to be loaded to memory (cached), which will result in more memory consumption.
|
|
|
|
|
2018-05-23 08:39:04 -04:00
|
|
|
[float]
|
2019-07-19 14:35:36 -04:00
|
|
|
====== Custom formats
|
2018-05-23 08:39:04 -04:00
|
|
|
|
|
|
|
While most fields do not support custom formats, some of them do:
|
2018-06-26 13:15:56 -04:00
|
|
|
|
2018-05-23 08:39:04 -04:00
|
|
|
- <<date,Date>> fields can take any <<mapping-date-format,date format>>.
|
|
|
|
- <<number,Numeric>> fields accept a https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html[DecimalFormat pattern].
|
|
|
|
|
2019-01-30 04:31:51 -05:00
|
|
|
By default fields are formatted based on a sensible configuration that depends
|
|
|
|
on their mappings: `long`, `double` and other numeric fields are formatted as
|
|
|
|
numbers, `keyword` fields are formatted as strings, `date` fields are formatted
|
|
|
|
with the configured `date` format, etc.
|
2018-05-23 08:39:04 -04:00
|
|
|
|
2019-05-31 11:53:59 -04:00
|
|
|
NOTE: On its own, `docvalue_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 docvalue field. To access nested fields, `docvalue_fields`
|
2019-07-19 09:16:35 -04:00
|
|
|
must be used within an <<request-body-search-inner-hits, `inner_hits`>> block.
|