OpenSearch/docs/reference/mapping/params/store.asciidoc

73 lines
2.1 KiB
Plaintext
Raw Normal View History

[[mapping-store]]
=== `store`
2016-03-10 08:34:05 -05:00
By default, field values are <<mapping-index,indexed>> to make them searchable,
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
<<search-request-source-filtering,source filtering>>.
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:
[source,js]
--------------------------------------------------
Update the default for include_type_name to false. (#37285) * Default include_type_name to false for get and put mappings. * Default include_type_name to false for get field mappings. * Add a constant for the default include_type_name value. * Default include_type_name to false for get and put index templates. * Default include_type_name to false for create index. * Update create index calls in REST documentation to use include_type_name=true. * Some minor clean-ups around the get index API. * In REST tests, use include_type_name=true by default for index creation. * Make sure to use 'expression == false'. * Clarify the different IndexTemplateMetaData toXContent methods. * Fix FullClusterRestartIT#testSnapshotRestore. * Fix the ml_anomalies_default_mappings test. * Fix GetFieldMappingsResponseTests and GetIndexTemplateResponseTests. We make sure to specify include_type_name=true during xContent parsing, so we continue to test the legacy typed responses. XContent generation for the typeless responses is currently only covered by REST tests, but we will be adding unit test coverage for these as we implement each typeless API in the Java HLRC. This commit also refactors GetMappingsResponse to follow the same appraoch as the other mappings-related responses, where we read include_type_name out of the xContent params, instead of creating a second toXContent method. This gives better consistency in the response parsing code. * Fix more REST tests. * Improve some wording in the create index documentation. * Add a note about types removal in the create index docs. * Fix SmokeTestMonitoringWithSecurityIT#testHTTPExporterWithSSL. * Make sure to mention include_type_name in the REST docs for affected APIs. * Make sure to use 'expression == false' in FullClusterRestartIT. * Mention include_type_name in the REST templates docs.
2019-01-14 16:08:01 -05:00
PUT my_index?include_type_name=true
{
"mappings": {
"_doc": {
"properties": {
"title": {
2016-03-18 12:01:27 -04:00
"type": "text",
"store": true <1>
},
"date": {
"type": "date",
"store": true <1>
},
"content": {
2016-03-18 12:01:27 -04:00
"type": "text"
}
}
}
}
}
PUT my_index/_doc/1
{
"title": "Some short title",
"date": "2015-01-01",
"content": "A very long content field..."
}
GET my_index/_search
{
"stored_fields": [ "title", "date" ] <2>
}
--------------------------------------------------
// CONSOLE
<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>>).