fielddata.asciidoc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. [float]
  23. [[fielddata-circuit-breaker]]
  24. === Field data circuit breaker
  25. The field data circuit breaker allows Elasticsearch to estimate the amount of
  26. memory a field will required to be loaded into memory. It can then prevent the
  27. field data loading by raising and exception. By default the limit is configured
  28. to 80% of the maximum JVM heap. It can be configured with the following
  29. parameters:
  30. [cols="<,<",options="header",]
  31. |=======================================================================
  32. |Setting |Description
  33. |`indices.fielddata.breaker.limit` |Maximum size of estimated field data
  34. to allow loading. Defaults to 80% of the maximum JVM heap.
  35. |`indices.fielddata.breaker.overhead` |A constant that all field data
  36. estimations are multiplied with to determine a final estimation. Defaults to
  37. 1.03
  38. |=======================================================================
  39. Both the `indices.fielddata.breaker.limit` and
  40. `indices.fielddata.breaker.overhead` can be changed dynamically using the
  41. cluster update settings API.
  42. [float]
  43. [[fielddata-monitoring]]
  44. === Monitoring field data
  45. You can monitor memory usage for field data as well as the field data circuit
  46. breaker using
  47. <<cluster-nodes-stats,Nodes Stats API>>
  48. [[fielddata-formats]]
  49. == Field data formats
  50. The field data format controls how field data should be stored.
  51. Depending on the field type, there might be several field data types
  52. available. In particular, string and numeric types support the `doc_values`
  53. format which allows for computing the field data data-structures at indexing
  54. time and storing them on disk. Although it will make the index larger and may
  55. be slightly slower, this implementation will be more near-realtime-friendly
  56. and will require much less memory from the JVM than other implementations.
  57. Here is an example of how to configure the `tag` field to use the `fst` field
  58. data format.
  59. [source,js]
  60. --------------------------------------------------
  61. {
  62. tag: {
  63. type: "string",
  64. fielddata: {
  65. format: "fst"
  66. }
  67. }
  68. }
  69. --------------------------------------------------
  70. It is possible to change the field data format (and the field data settings
  71. in general) on a live index by using the update mapping API. When doing so,
  72. field data which had already been loaded for existing segments will remain
  73. alive while new segments will use the new field data configuration. Thanks to
  74. the background merging process, all segments will eventually use the new
  75. field data format.
  76. [float]
  77. ==== String field data types
  78. `paged_bytes` (default)::
  79. Stores unique terms sequentially in a large buffer and maps documents to
  80. the indices of the terms they contain in this large buffer.
  81. `fst`::
  82. Stores terms in a FST. Slower to build than `paged_bytes` but can help lower
  83. memory usage if many terms share common prefixes and/or suffixes.
  84. `doc_values`::
  85. Computes and stores field data data-structures on disk at indexing time.
  86. Lowers memory usage but only works on non-analyzed strings (`index`: `no` or
  87. `not_analyzed`) and doesn't support filtering.
  88. [float]
  89. ==== Numeric field data types
  90. `array` (default)::
  91. Stores field values in memory using arrays.
  92. `doc_values`::
  93. Computes and stores field data data-structures on disk at indexing time.
  94. Doesn't support filtering.
  95. [float]
  96. ==== Geo point field data types
  97. `array` (default)::
  98. Stores latitudes and longitudes in arrays.
  99. `doc_values`::
  100. Computes and stores field data data-structures on disk at indexing time.
  101. [float]
  102. === Fielddata loading
  103. By default, field data is loaded lazily, ie. the first time that a query that
  104. requires them is executed. However, this can make the first requests that
  105. follow a merge operation quite slow since fielddata loading is a heavy
  106. operation.
  107. It is possible to force field data to be loaded and cached eagerly through the
  108. `loading` setting of fielddata:
  109. [source,js]
  110. --------------------------------------------------
  111. {
  112. category: {
  113. type: "string",
  114. fielddata: {
  115. loading: "eager"
  116. }
  117. }
  118. }
  119. --------------------------------------------------
  120. [float]
  121. ==== Disabling field data loading
  122. Field data can take a lot of RAM so it makes sense to disable field data
  123. loading on the fields that don't need field data, for example those that are
  124. used for full-text search only. In order to disable field data loading, just
  125. change the field data format to `disabled`. When disabled, all requests that
  126. will try to load field data, e.g. when they include aggregations and/or sorting,
  127. will return an error.
  128. [source,js]
  129. --------------------------------------------------
  130. {
  131. text: {
  132. type: "string",
  133. fielddata: {
  134. format: "disabled"
  135. }
  136. }
  137. }
  138. --------------------------------------------------
  139. The `disabled` format is supported by all field types.
  140. [float]
  141. [[field-data-filtering]]
  142. === Filtering fielddata
  143. It is possible to control which field values are loaded into memory,
  144. which is particularly useful for string fields. When specifying the
  145. <<mapping-core-types,mapping>> for a field, you
  146. can also specify a fielddata filter.
  147. Fielddata filters can be changed using the
  148. <<indices-put-mapping,PUT mapping>>
  149. API. After changing the filters, use the
  150. <<indices-clearcache,Clear Cache>> API
  151. to reload the fielddata using the new filters.
  152. [float]
  153. ==== Filtering by frequency:
  154. The frequency filter allows you to only load terms whose frequency falls
  155. between a `min` and `max` value, which can be expressed an absolute
  156. number or as a percentage (eg `0.01` is `1%`). Frequency is calculated
  157. *per segment*. Percentages are based on the number of docs which have a
  158. value for the field, as opposed to all docs in the segment.
  159. Small segments can be excluded completely by specifying the minimum
  160. number of docs that the segment should contain with `min_segment_size`:
  161. [source,js]
  162. --------------------------------------------------
  163. {
  164. tag: {
  165. type: "string",
  166. fielddata: {
  167. filter: {
  168. frequency: {
  169. min: 0.001,
  170. max: 0.1,
  171. min_segment_size: 500
  172. }
  173. }
  174. }
  175. }
  176. }
  177. --------------------------------------------------
  178. [float]
  179. ==== Filtering by regex
  180. Terms can also be filtered by regular expression - only values which
  181. match the regular expression are loaded. Note: the regular expression is
  182. applied to each term in the field, not to the whole field value. For
  183. instance, to only load hashtags from a tweet, we can use a regular
  184. expression which matches terms beginning with `#`:
  185. [source,js]
  186. --------------------------------------------------
  187. {
  188. tweet: {
  189. type: "string",
  190. analyzer: "whitespace"
  191. fielddata: {
  192. filter: {
  193. regex: {
  194. pattern: "^#.*"
  195. }
  196. }
  197. }
  198. }
  199. }
  200. --------------------------------------------------
  201. [float]
  202. ==== Combining filters
  203. The `frequency` and `regex` filters can be combined:
  204. [source,js]
  205. --------------------------------------------------
  206. {
  207. tweet: {
  208. type: "string",
  209. analyzer: "whitespace"
  210. fielddata: {
  211. filter: {
  212. regex: {
  213. pattern: "^#.*",
  214. },
  215. frequency: {
  216. min: 0.001,
  217. max: 0.1,
  218. min_segment_size: 500
  219. }
  220. }
  221. }
  222. }
  223. }
  224. --------------------------------------------------