2015-08-06 11:24:29 -04:00
|
|
|
[[mapping-store]]
|
|
|
|
=== `store`
|
|
|
|
|
2016-03-10 08:34:05 -05:00
|
|
|
By default, field values are <<mapping-index,indexed>> to make them searchable,
|
2015-08-06 11:24:29 -04:00
|
|
|
but they are not _stored_. This means that the field can be queried, but the
|
|
|
|
original field value cannot be retrieved.
|
|
|
|
|
|
|
|
Usually this doesn't matter. The field value is already part of the
|
|
|
|
<<mapping-source-field,`_source` field>>, which is stored by default. If you
|
|
|
|
only want to retrieve the value of a single field or of a few fields, instead
|
|
|
|
of the whole `_source`, then this can be achieved with
|
2020-06-11 11:25:04 -04:00
|
|
|
<<source-filtering,source filtering>>.
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
In certain situations it can make sense to `store` a field. For instance, if
|
|
|
|
you have a document with a `title`, a `date`, and a very large `content`
|
|
|
|
field, you may want to retrieve just the `title` and the `date` without having
|
|
|
|
to extract those fields from a large `_source` field:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"properties": {
|
|
|
|
"title": {
|
|
|
|
"type": "text",
|
|
|
|
"store": true <1>
|
|
|
|
},
|
|
|
|
"date": {
|
|
|
|
"type": "date",
|
|
|
|
"store": true <1>
|
|
|
|
},
|
|
|
|
"content": {
|
|
|
|
"type": "text"
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001/_doc/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"title": "Some short title",
|
|
|
|
"date": "2015-01-01",
|
|
|
|
"content": "A very long content field..."
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
GET my-index-000001/_search
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
2016-06-21 05:27:27 -04:00
|
|
|
"stored_fields": [ "title", "date" ] <2>
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-06 11:31:13 -04:00
|
|
|
|
2015-08-06 11:24:29 -04:00
|
|
|
<1> The `title` and `date` fields are stored.
|
|
|
|
<2> This request will retrieve the values of the `title` and `date` fields.
|
|
|
|
|
|
|
|
[NOTE]
|
|
|
|
.Stored fields returned as arrays
|
|
|
|
======================================
|
|
|
|
|
|
|
|
For consistency, stored fields are always returned as an _array_ because there
|
|
|
|
is no way of knowing if the original field value was a single value, multiple
|
|
|
|
values, or an empty array.
|
|
|
|
|
|
|
|
If you need the original value, you should retrieve it from the `_source`
|
|
|
|
field instead.
|
|
|
|
|
|
|
|
======================================
|
|
|
|
|
|
|
|
Another situation where it can make sense to make a field stored is for those
|
|
|
|
that don't appear in the `_source` field (such as <<copy-to,`copy_to` fields>>).
|