doc_values
Most fields are 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 different data access pattern. Instead of looking up the term and finding documents, we need to be able to look up the document and find the terms that it has in a field.
The doc_values field is an on-disk data structure that is built at index time and enables efficient data access. It stores the same values as _source, but in a column-oriented format that is more efficient for sorting and aggregations.
Doc values are supported on most field types, excluding text and annotated_text fields. See also Disabling doc values.
Doc-value-only fields
Numeric types, date types, the boolean type, ip type, geo_point type and the keyword type can also be queried when they are not indexed but only have doc values enabled. Query performance on doc values is much slower than on index structures, but offers an interesting tradeoff between disk usage and query performance for fields that are only rarely queried and where query performance is not as important. This makes doc-value-only fields a good fit for fields that are not expected to be normally used for filtering, for example gauges or counters on metric data.
Doc-value-only fields can be configured as follows:
resp = client.indices.create(
index="my-index-000001",
mappings={
"properties": {
"status_code": {
"type": "long"
},
"session_id": {
"type": "long",
"index": False
}
}
},
)
print(resp) response = client.indices.create(
index: 'my-index-000001',
body: {
mappings: {
properties: {
status_code: {
type: 'long'
},
session_id: {
type: 'long',
index: false
}
}
}
}
)
puts response const response = await client.indices.create({
index: "my-index-000001",
mappings: {
properties: {
status_code: {
type: "long",
},
session_id: {
type: "long",
index: false,
},
},
},
});
console.log(response); PUT my-index-000001
{
"mappings": {
"properties": {
"status_code": {
"type": "long"
},
"session_id": {
"type": "long",
"index": false
}
}
}
} | The | |
| The |
Disabling doc values
For all fields that support them, doc_values are enabled by default. In some field types, such as search_as_you_type, doc_values appear in API responses but can’t be configured. Setting doc_values for these fields might result in an error or have no effect.
If you’re certain you don’t need to sort or aggregate on a field or access its value from a script, you can disable doc_values in order to save disk space:
resp = client.indices.create(
index="my-index-000001",
mappings={
"properties": {
"status_code": {
"type": "keyword"
},
"session_id": {
"type": "keyword",
"doc_values": False
}
}
},
)
print(resp) response = client.indices.create(
index: 'my-index-000001',
body: {
mappings: {
properties: {
status_code: {
type: 'keyword'
},
session_id: {
type: 'keyword',
doc_values: false
}
}
}
}
)
puts response const response = await client.indices.create({
index: "my-index-000001",
mappings: {
properties: {
status_code: {
type: "keyword",
},
session_id: {
type: "keyword",
doc_values: false,
},
},
},
});
console.log(response); PUT my-index-000001
{
"mappings": {
"properties": {
"status_code": {
"type": "keyword"
},
"session_id": {
"type": "keyword",
"doc_values": false
}
}
}
} | The | |
| The |
You cannot disable doc values for wildcard fields.
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/doc-values.html