doc-values.asciidoc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. <<number,Numeric types>>, <<date,date types>>, and the <<keyword, keyword type>>
  17. can also be queried using term or range-based queries
  18. when they are not <<mapping-index,indexed>> but only have doc values enabled.
  19. Query performance on doc values is much slower than on index structures, but
  20. offers an interesting tradeoff between disk usage and query performance for
  21. fields that are only rarely queried and where query performance is not as
  22. important.
  23. All fields which support doc values have them enabled by default. If you are
  24. sure that you don't need to sort or aggregate on a field, or access the field
  25. value from a script, you can disable doc values in order to save disk space:
  26. [source,console]
  27. --------------------------------------------------
  28. PUT my-index-000001
  29. {
  30. "mappings": {
  31. "properties": {
  32. "status_code": { <1>
  33. "type": "keyword"
  34. },
  35. "session_id": { <2>
  36. "type": "keyword",
  37. "doc_values": false
  38. }
  39. }
  40. }
  41. }
  42. --------------------------------------------------
  43. <1> The `status_code` field has `doc_values` enabled by default.
  44. <2> The `session_id` has `doc_values` disabled, but can still be queried.
  45. NOTE: You cannot disable doc values for <<wildcard-field-type,`wildcard`>>
  46. fields.