2015-08-06 11:24:29 -04:00
|
|
|
[[doc-values]]
|
|
|
|
=== `doc_values`
|
|
|
|
|
|
|
|
Most fields are <<mapping-index,indexed>> by default, which makes them
|
|
|
|
searchable. The inverted index allows queries to look up the search term in
|
|
|
|
unique sorted list of terms, and from that immediately have access to the list
|
|
|
|
of documents that contain the term.
|
|
|
|
|
|
|
|
Sorting, aggregations, and access to field values in scripts requires a
|
2016-01-18 16:38:13 -05:00
|
|
|
different data access pattern. Instead of looking up the term and finding
|
2015-08-06 11:24:29 -04:00
|
|
|
documents, we need to be able to look up the document and find the terms that
|
2015-12-03 23:53:48 -05:00
|
|
|
it has in a field.
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
Doc values are the on-disk data structure, built at document index time, which
|
2015-11-09 17:25:07 -05:00
|
|
|
makes this data access pattern possible. They store the same values as the
|
|
|
|
`_source` but in a column-oriented fashion that is way more efficient for
|
|
|
|
sorting and aggregations. Doc values are supported on almost all field types,
|
|
|
|
with the __notable exception of `analyzed` string fields__.
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
All fields which support doc values have them enabled by default. If you are
|
|
|
|
sure that you don't need to sort or aggregate on a field, or access the field
|
|
|
|
value from a script, you can disable doc values in order to save disk space:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT my_index
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"properties": {
|
|
|
|
"status_code": { <1>
|
|
|
|
"type": "keyword"
|
|
|
|
},
|
|
|
|
"session_id": { <2>
|
|
|
|
"type": "keyword",
|
|
|
|
"doc_values": false
|
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 `status_code` field has `doc_values` enabled by default.
|
|
|
|
<2> The `session_id` has `doc_values` disabled, but can still be queried.
|
|
|
|
|