fielddata.asciidoc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. [[index-modules-fielddata]]
  2. == Field data
  3. The field data cache is used mainly when sorting on or faceting on a
  4. field. It loads all the field values to memory in order to provide fast
  5. document based access to those values. The field data cache can be
  6. expensive to build for a field, so its recommended to have enough memory
  7. to allocate it, and to keep it loaded.
  8. The amount of memory used for the field
  9. data cache can be controlled using `indices.fielddata.cache.size`. Note:
  10. reloading the field data which does not fit into your cache will be expensive
  11. and perform poorly.
  12. [cols="<,<",options="header",]
  13. |=======================================================================
  14. |Setting |Description
  15. |`indices.fielddata.cache.size` |The max size of the field data cache,
  16. eg `30%` of node heap space, or an absolute value, eg `12GB`. Defaults
  17. to unbounded.
  18. |`indices.fielddata.cache.expire` |A time based setting that expires
  19. field data after a certain time of inactivity. Defaults to `-1`. For
  20. example, can be set to `5m` for a 5 minute expiry.
  21. |=======================================================================
  22. === Field data formats
  23. The field data format controls how field data should be stored.
  24. Depending on the field type, there might be several field data types
  25. available. In particular, string and numeric types support the `doc_values`
  26. format which allows for computing the field data data-structures at indexing
  27. time and storing them on disk. Although it will make the index larger and may
  28. be slightly slower, this implementation will be more near-realtime-friendly
  29. and will require much less memory from the JVM than other implementations.
  30. Here is an example of how to configure the `tag` field to use the `fst` field
  31. data format.
  32. [source,js]
  33. --------------------------------------------------
  34. {
  35. tag: {
  36. type: "string",
  37. fielddata: {
  38. format: "fst"
  39. }
  40. }
  41. }
  42. --------------------------------------------------
  43. It is possible to change the field data format (and the field data settings
  44. in general) on a live index by using the update mapping API. When doing so,
  45. field data which had already been loaded for existing segments will remain
  46. alive while new segments will use the new field data configuration. Thanks to
  47. the background merging process, all segments will eventually use the new
  48. field data format.
  49. [float]
  50. ==== Disallowing field data loading
  51. Field data can take a lot of RAM so it makes sense to disable field data
  52. loading on the fields that don't need field data, for example those that are
  53. used for full-text search only. In order to disable field data loading, just
  54. change the field data type to `disabled`. Request that will try to load field
  55. data on any field which is configured with this format will then return an
  56. error.
  57. The `disabled` format is supported by all field types.
  58. [float]
  59. ==== String field data types
  60. `paged_bytes` (default)::
  61. Stores unique terms sequentially in a large buffer and maps documents to
  62. the indices of the terms they contain in this large buffer.
  63. `fst`::
  64. Stores terms in a FST. Slower to build than `paged_bytes` but can help lower
  65. memory usage if many terms share common prefixes and/or suffixes.
  66. `doc_values`::
  67. Computes and stores field data data-structures on disk at indexing time.
  68. Lowers memory usage but only works on non-analyzed strings (`index`: `no` or
  69. `not_analyzed`) and doesn't support filtering.
  70. [float]
  71. ==== Numeric field data types
  72. `array` (default)::
  73. Stores field values in memory using arrays.
  74. `doc_values`::
  75. Computes and stores field data data-structures on disk at indexing time.
  76. Doesn't support filtering.
  77. [float]
  78. ==== Geo point field data types
  79. `array` (default)::
  80. Stores latitudes and longitudes in arrays.
  81. [float]
  82. === Fielddata loading
  83. By default, field data is loaded lazily, on the first time that a query that
  84. requires field data is fired. However, this can make the first requests that
  85. follow a merge operation quite slow since fielddata loading is a heavy
  86. operation.
  87. It is possible to force field data to be loaded and cached eagerly through the
  88. `loading` setting of fielddata:
  89. [source,js]
  90. --------------------------------------------------
  91. {
  92. category: {
  93. type: "string",
  94. fielddata: {
  95. loading: "eager"
  96. }
  97. }
  98. }
  99. --------------------------------------------------
  100. [float]
  101. [[field-data-filtering]]
  102. === Filtering fielddata
  103. It is possible to control which field values are loaded into memory,
  104. which is particularly useful for string fields. When specifying the
  105. <<mapping-core-types,mapping>> for a field, you
  106. can also specify a fielddata filter.
  107. Fielddata filters can be changed using the
  108. <<indices-put-mapping,PUT mapping>>
  109. API. After changing the filters, use the
  110. <<indices-clearcache,Clear Cache>> API
  111. to reload the fielddata using the new filters.
  112. [float]
  113. ==== Filtering by frequency:
  114. The frequency filter allows you to only load terms whose frequency falls
  115. between a `min` and `max` value, which can be expressed an absolute
  116. number or as a percentage (eg `0.01` is `1%`). Frequency is calculated
  117. *per segment*. Percentages are based on the number of docs which have a
  118. value for the field, as opposed to all docs in the segment.
  119. Small segments can be excluded completely by specifying the minimum
  120. number of docs that the segment should contain with `min_segment_size`:
  121. [source,js]
  122. --------------------------------------------------
  123. {
  124. tag: {
  125. type: "string",
  126. fielddata: {
  127. filter: {
  128. frequency: {
  129. min: 0.001,
  130. max: 0.1,
  131. min_segment_size: 500
  132. }
  133. }
  134. }
  135. }
  136. }
  137. --------------------------------------------------
  138. [float]
  139. ==== Filtering by regex
  140. Terms can also be filtered by regular expression - only values which
  141. match the regular expression are loaded. Note: the regular expression is
  142. applied to each term in the field, not to the whole field value. For
  143. instance, to only load hashtags from a tweet, we can use a regular
  144. expression which matches terms beginning with `#`:
  145. [source,js]
  146. --------------------------------------------------
  147. {
  148. tweet: {
  149. type: "string",
  150. analyzer: "whitespace"
  151. fielddata: {
  152. filter: {
  153. regex: {
  154. pattern: "^#.*"
  155. }
  156. }
  157. }
  158. }
  159. }
  160. --------------------------------------------------
  161. [float]
  162. ==== Combining filters
  163. The `frequency` and `regex` filters can be combined:
  164. [source,js]
  165. --------------------------------------------------
  166. {
  167. tweet: {
  168. type: "string",
  169. analyzer: "whitespace"
  170. fielddata: {
  171. filter: {
  172. regex: {
  173. pattern: "^#.*",
  174. },
  175. frequency: {
  176. min: 0.001,
  177. max: 0.1,
  178. min_segment_size: 500
  179. }
  180. }
  181. }
  182. }
  183. }
  184. --------------------------------------------------
  185. [float]
  186. [[field-data-monitoring]]
  187. === Monitoring field data
  188. You can monitor memory usage for field data using
  189. <<cluster-nodes-stats,Nodes Stats API>>