doc-values.asciidoc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. [[doc-values]]
  2. === `doc_values`
  3. Most fields are <<mapping-index,indexed>> by default, which makes them
  4. searchable. The inverted index allows queries to look up the search term in
  5. unique sorted list of terms, and from that immediately have access to the list
  6. of documents that contain the term.
  7. Sorting, aggregations, and access to field values in scripts requires a
  8. different data access pattern. Instead of looking up the term and finding
  9. documents, we need to be able to look up the document and find the terms that
  10. it has in a field.
  11. Doc values are the on-disk data structure, built at document index time, which
  12. makes this data access pattern possible. They store the same values as the
  13. `_source` but in a column-oriented fashion that is way more efficient for
  14. sorting and aggregations. Doc values are supported on almost all field types,
  15. with the __notable exception of `text` and `annotated_text` fields__.
  16. All fields which support doc values have them enabled by default. If you are
  17. sure that you don't need to sort or aggregate on a field, or access the field
  18. value from a script, you can disable doc values in order to save disk space:
  19. [source,console]
  20. --------------------------------------------------
  21. PUT my_index
  22. {
  23. "mappings": {
  24. "properties": {
  25. "status_code": { <1>
  26. "type": "keyword"
  27. },
  28. "session_id": { <2>
  29. "type": "keyword",
  30. "doc_values": false
  31. }
  32. }
  33. }
  34. }
  35. --------------------------------------------------
  36. <1> The `status_code` field has `doc_values` enabled by default.
  37. <2> The `session_id` has `doc_values` disabled, but can still be queried.