doc-values.asciidoc 2.2 KB

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