doc-values.asciidoc 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. [[doc-value-only-fields]]
  17. ==== Doc-value-only fields
  18. <<number,Numeric types>>, <<date,date types>>, the <<boolean,boolean type>>,
  19. <<ip,ip type>>, <<geo-point,geo_point type>> and the <<keyword,keyword type>>
  20. can also be queried when they are not <<mapping-index,indexed>> but only
  21. have doc values enabled.
  22. Query performance on doc values is much slower than on index structures, but
  23. offers an interesting tradeoff between disk usage and query performance for
  24. fields that are only rarely queried and where query performance is not as
  25. important. This makes doc-value-only fields a good fit for fields that are
  26. not expected to be normally used for filtering, for example gauges or
  27. counters on metric data.
  28. Doc-value-only fields can be configured as follows:
  29. [source,console]
  30. --------------------------------------------------
  31. PUT my-index-000001
  32. {
  33. "mappings": {
  34. "properties": {
  35. "status_code": { <1>
  36. "type": "long"
  37. },
  38. "session_id": { <2>
  39. "type": "long",
  40. "index": false
  41. }
  42. }
  43. }
  44. }
  45. --------------------------------------------------
  46. <1> The `status_code` field is a regular long field.
  47. <2> The `session_id` field has `index` disabled, and is therefore a
  48. doc-value-only long field as doc values are enabled by default.
  49. ==== Disabling doc values
  50. All fields which support doc values have them enabled by default. If you are
  51. sure that you don't need to sort or aggregate on a field, or access the field
  52. value from a script, you can disable doc values in order to save disk space:
  53. [source,console]
  54. --------------------------------------------------
  55. PUT my-index-000001
  56. {
  57. "mappings": {
  58. "properties": {
  59. "status_code": { <1>
  60. "type": "keyword"
  61. },
  62. "session_id": { <2>
  63. "type": "keyword",
  64. "doc_values": false
  65. }
  66. }
  67. }
  68. }
  69. --------------------------------------------------
  70. <1> The `status_code` field has `doc_values` enabled by default.
  71. <2> The `session_id` has `doc_values` disabled, but can still be queried.
  72. NOTE: You cannot disable doc values for <<wildcard-field-type,`wildcard`>>
  73. fields.