fielddata.asciidoc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. [[fielddata]]
  2. === `fielddata`
  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 lookup 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. Most fields can use index-time, on-disk <<doc-values,`doc_values`>> to support
  12. this type of data access pattern, but `text` fields do not support `doc_values`.
  13. Instead, `text` strings use a query-time data structure called
  14. `fielddata`. This data structure is built on demand the first time that a
  15. field is used for aggregations, sorting, or is accessed in a script. It is built
  16. by reading the entire inverted index for each segment from disk, inverting the
  17. term ↔︎ document relationship, and storing the result in memory, in the
  18. JVM heap.
  19. Loading fielddata is an expensive process so it is disabled by default. Also,
  20. when enabled, once it has been loaded, it remains in memory for the lifetime of
  21. the segment.
  22. [WARNING]
  23. .Fielddata can fill up your heap space
  24. ==============================================================================
  25. Fielddata can consume a lot of heap space, especially when loading high
  26. cardinality `text` fields. Most of the time, it doesn't make sense
  27. to sort or aggregate on `text` fields (with the notable exception
  28. of the
  29. <<search-aggregations-bucket-significantterms-aggregation,`significant_terms`>>
  30. aggregation). Always think about whether a <<keyword,`keyword`>> field (which can
  31. use `doc_values`) would be a better fit for your use case.
  32. ==============================================================================
  33. TIP: The `fielddata.*` settings must have the same settings for fields of the
  34. same name in the same index. Its value can be updated on existing fields
  35. using the <<indices-put-mapping,PUT mapping API>>.
  36. [[global-ordinals]]
  37. .Global ordinals
  38. *****************************************
  39. Global ordinals is a data-structure on top of fielddata and doc values, that
  40. maintains an incremental numbering for each unique term in a lexicographic
  41. order. Each term has a unique number and the number of term 'A' is lower than
  42. the number of term 'B'. Global ordinals are only supported on string fields.
  43. Fielddata and doc values also have ordinals, which is a unique numbering for all terms
  44. in a particular segment and field. Global ordinals just build on top of this,
  45. by providing a mapping between the segment ordinals and the global ordinals,
  46. the latter being unique across the entire shard.
  47. Global ordinals are used for features that use segment ordinals, such as
  48. sorting and the terms aggregation, to improve the execution time. A terms
  49. aggregation relies purely on global ordinals to perform the aggregation at the
  50. shard level, then converts global ordinals to the real term only for the final
  51. reduce phase, which combines results from different shards.
  52. Global ordinals for a specified field are tied to _all the segments of a
  53. shard_, while fielddata and doc values ordinals are tied to a single segment.
  54. which is different than for field data for a specific field which is tied to a
  55. single segment. For this reason global ordinals need to be entirely rebuilt
  56. whenever a once new segment becomes visible.
  57. The loading time of global ordinals depends on the number of terms in a field, but in general
  58. it is low, since it source field data has already been loaded. The memory overhead of global
  59. ordinals is a small because it is very efficiently compressed. Eager loading of global ordinals
  60. can move the loading time from the first search request, to the refresh itself.
  61. *****************************************
  62. [[field-data-filtering]]
  63. ==== `fielddata_frequency_filter`
  64. Fielddata filtering can be used to reduce the number of terms loaded into
  65. memory, and thus reduce memory usage. Terms can be filtered by _frequency_:
  66. The frequency filter allows you to only load terms whose term frequency falls
  67. between a `min` and `max` value, which can be expressed an absolute
  68. number (when the number is bigger than 1.0) or as a percentage
  69. (eg `0.01` is `1%` and `1.0` is `100%`). Frequency is calculated
  70. *per segment*. Percentages are based on the number of docs which have a
  71. value for the field, as opposed to all docs in the segment.
  72. Small segments can be excluded completely by specifying the minimum
  73. number of docs that the segment should contain with `min_segment_size`:
  74. [source,js]
  75. --------------------------------------------------
  76. PUT my_index
  77. {
  78. "mappings": {
  79. "my_type": {
  80. "properties": {
  81. "tag": {
  82. "type": "text",
  83. "fielddata": true,
  84. "fielddata_frequency_filter": {
  85. "min": 0.001,
  86. "max": 0.1,
  87. "min_segment_size": 500
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. --------------------------------------------------
  95. // AUTOSENSE