codec.asciidoc 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. [[index-modules-codec]]
  2. == Codec module
  3. Codecs define how documents are written to disk and read from disk. The
  4. postings format is the part of the codec that is responsible for reading
  5. and writing the term dictionary, postings lists and positions, as well as the payloads
  6. and offsets stored in the postings list. The doc values format is
  7. responsible for reading column-stride storage for a field and is typically
  8. used for sorting or faceting. When a field doesn't have doc values enabled,
  9. it is still possible to sort or facet by loading field values from the
  10. inverted index into main memory.
  11. Configuring custom postings or doc values formats is an expert feature and
  12. most likely using the builtin formats will suit your needs as is described
  13. in the <<mapping-core-types,mapping section>>.
  14. [WARNING]
  15. Only the default codec, postings format and doc values format are supported:
  16. other formats may break backward compatibility between minor versions of
  17. Elasticsearch, requiring data to be reindexed.
  18. [float]
  19. [[custom-postings]]
  20. === Configuring a custom postings format
  21. A custom postings format can be defined in the index settings in the
  22. `codec` part. The `codec` part can be configured when creating an index
  23. or updating index settings. An example on how to define your custom
  24. postings format:
  25. [source,js]
  26. --------------------------------------------------
  27. curl -XPUT 'http://localhost:9200/twitter/' -d '{
  28. "settings" : {
  29. "index" : {
  30. "codec" : {
  31. "postings_format" : {
  32. "my_format" : {
  33. "type" : "pulsing",
  34. "freq_cut_off" : "5"
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }'
  41. --------------------------------------------------
  42. Then when defining your mapping you can use the `my_format` name in the
  43. `postings_format` option as the example below illustrates:
  44. [source,js]
  45. --------------------------------------------------
  46. {
  47. "person" : {
  48. "properties" : {
  49. "second_person_id" : {"type" : "string", "postings_format" : "my_format"}
  50. }
  51. }
  52. }
  53. --------------------------------------------------
  54. [float]
  55. === Available postings formats
  56. [float]
  57. [[direct-postings]]
  58. ==== Direct postings format
  59. Wraps the default postings format for on-disk storage, but then at read
  60. time loads and stores all terms & postings directly in RAM. This
  61. postings format makes no effort to compress the terms and posting list
  62. and therefore is memory intensive, but because of this it gives a
  63. substantial increase in search performance. Because this holds all term
  64. bytes as a single byte[], you cannot have more than 2.1GB worth of terms
  65. in a single segment.
  66. This postings format offers the following parameters:
  67. `min_skip_count`::
  68. The minimum number terms with a shared prefix to
  69. allow a skip pointer to be written. The default is *8*.
  70. `low_freq_cutoff`::
  71. Terms with a lower document frequency use a
  72. single array object representation for postings and positions. The
  73. default is *32*.
  74. Type name: `direct`
  75. [float]
  76. [[memory-postings]]
  77. ==== Memory postings format
  78. A postings format that stores terms & postings (docs, positions,
  79. payloads) in RAM, using an FST. This postings format does write to disk,
  80. but loads everything into memory. The memory postings format has the
  81. following options:
  82. `pack_fst`::
  83. A boolean option that defines if the in memory structure
  84. should be packed once its build. Packed will reduce the size for the
  85. data-structure in memory but requires more memory during building.
  86. Default is *false*.
  87. `acceptable_overhead_ratio`::
  88. The compression ratio specified as a
  89. float, that is used to compress internal structures. Example ratios `0`
  90. (Compact, no memory overhead at all, but the returned implementation may
  91. be slow), `0.5` (Fast, at most 50% memory overhead, always select a
  92. reasonably fast implementation), `7` (Fastest, at most 700% memory
  93. overhead, no compression). Default is `0.2`.
  94. Type name: `memory`
  95. [float]
  96. [[bloom-postings]]
  97. ==== Bloom filter posting format
  98. The bloom filter postings format wraps a delegate postings format and on
  99. top of this creates a bloom filter that is written to disk. During
  100. opening this bloom filter is loaded into memory and used to offer
  101. "fast-fail" reads. This postings format is useful for low doc-frequency
  102. fields such as primary keys. The bloom filter postings format has the
  103. following options:
  104. `delegate`::
  105. The name of the configured postings format that the
  106. bloom filter postings format will wrap.
  107. `fpp`::
  108. The desired false positive probability specified as a
  109. floating point number between 0 and 1.0. The `fpp` can be configured for
  110. multiple expected insertions. Example expression: *10k=0.01,1m=0.03*. If
  111. number docs per index segment is larger than *1m* then use *0.03* as fpp
  112. and if number of docs per segment is larger than *10k* use *0.01* as
  113. fpp. The last fallback value is always *0.03*. This example expression
  114. is also the default.
  115. Type name: `bloom`
  116. [[codec-bloom-load]]
  117. [TIP]
  118. ==================================================
  119. As of 1.4, the bloom filters are no longer loaded at search time by
  120. default: they consume ~10 bits per unique id value, which can quickly
  121. add up for indices with many tiny documents, and separate performance
  122. improvements have made the performance gains with bloom filters very
  123. small.
  124. You can enable loading of the bloom filter at search time on a
  125. per-index basis by updating the index settings:
  126. [source,js]
  127. --------------------------------------------------
  128. PUT /old_index/_settings?index.codec.bloom.load=false
  129. --------------------------------------------------
  130. This setting, which defaults to `false`, can be updated on a live index. Note,
  131. however, that changing the value will cause the index to be reopened, which
  132. will invalidate any existing caches.
  133. ==================================================
  134. [float]
  135. [[pulsing-postings]]
  136. ==== Pulsing postings format
  137. The pulsing implementation in-lines the posting lists for very low
  138. frequent terms in the term dictionary. This is useful to improve lookup
  139. performance for low-frequent terms. This postings format offers the
  140. following parameters:
  141. `min_block_size`::
  142. The minimum block size the default Lucene term
  143. dictionary uses to encode on-disk blocks. Defaults to *25*.
  144. `max_block_size`::
  145. The maximum block size the default Lucene term
  146. dictionary uses to encode on-disk blocks. Defaults to *48*.
  147. `freq_cut_off`::
  148. The document frequency cut off where pulsing
  149. in-lines posting lists into the term dictionary. Terms with a document
  150. frequency less or equal to the cutoff will be in-lined. The default is
  151. *1*.
  152. Type name: `pulsing`
  153. [float]
  154. [[default-postings]]
  155. ==== Default postings format
  156. The default postings format has the following options:
  157. `min_block_size`::
  158. The minimum block size the default Lucene term
  159. dictionary uses to encode on-disk blocks. Defaults to *25*.
  160. `max_block_size`::
  161. The maximum block size the default Lucene term
  162. dictionary uses to encode on-disk blocks. Defaults to *48*.
  163. Type name: `default`
  164. [float]
  165. === Configuring a custom doc values format
  166. Custom doc values format can be defined in the index settings in the
  167. `codec` part. The `codec` part can be configured when creating an index
  168. or updating index settings. An example on how to define your custom
  169. doc values format:
  170. [source,js]
  171. --------------------------------------------------
  172. curl -XPUT 'http://localhost:9200/twitter/' -d '{
  173. "settings" : {
  174. "index" : {
  175. "codec" : {
  176. "doc_values_format" : {
  177. "my_format" : {
  178. "type" : "disk"
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }'
  185. --------------------------------------------------
  186. Then we defining your mapping your can use the `my_format` name in the
  187. `doc_values_format` option as the example below illustrates:
  188. [source,js]
  189. --------------------------------------------------
  190. {
  191. "product" : {
  192. "properties" : {
  193. "price" : {"type" : "integer", "doc_values_format" : "my_format"}
  194. }
  195. }
  196. }
  197. --------------------------------------------------
  198. [float]
  199. === Available doc values formats
  200. [float]
  201. ==== Memory doc values format
  202. A doc values format that stores all values in a FST in RAM. This format does
  203. write to disk but the whole data-structure is loaded into memory when reading
  204. the index. The memory postings format has no options.
  205. Type name: `memory`
  206. [float]
  207. ==== Disk doc values format
  208. A doc values format that stores and reads everything from disk. This is
  209. generally not a good idea to use it as it saves very little memory compared
  210. to the default doc values format although it can be significantly slower.
  211. The disk doc values format has no options.
  212. Type name: `disk`
  213. [float]
  214. ==== Default doc values format
  215. The default doc values format tries to make a good compromise between speed and
  216. memory usage by only loading into memory data-structures that matter for
  217. performance. This makes this doc values format a good fit for most use-cases.
  218. The default doc values format has no options.
  219. Type name: `default`