codec.asciidoc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 responsible for reading
  5. and writing the term dictionary, postings lists and positions, 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. **********************************
  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. **********************************
  19. [float]
  20. [[custom-postings]]
  21. === Configuring a custom postings format
  22. Custom postings format can be defined in the index settings in the
  23. `codec` part. The `codec` part can be configured when creating an index
  24. or updating index settings. An example on how to define your custom
  25. postings format:
  26. [source,js]
  27. --------------------------------------------------
  28. curl -XPUT 'http://localhost:9200/twitter/' -d '{
  29. "settings" : {
  30. "index" : {
  31. "codec" : {
  32. "postings_format" : {
  33. "my_format" : {
  34. "type" : "pulsing",
  35. "freq_cut_off" : "5"
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }'
  42. --------------------------------------------------
  43. Then we defining your mapping your can use the `my_format` name in the
  44. `postings_format` option as the example below illustrates:
  45. [source,js]
  46. --------------------------------------------------
  47. {
  48. "person" : {
  49. "properties" : {
  50. "second_person_id" : {"type" : "string", "postings_format" : "my_format"}
  51. }
  52. }
  53. }
  54. --------------------------------------------------
  55. [float]
  56. === Available postings formats
  57. [float]
  58. [[direct-postings]]
  59. ==== Direct postings format
  60. Wraps the default postings format for on-disk storage, but then at read
  61. time loads and stores all terms & postings directly in RAM. This
  62. postings format makes no effort to compress the terms and posting list
  63. and therefore is memory intensive, but because of this it gives a
  64. substantial increase in search performance. Because this holds all term
  65. bytes as a single byte[], you cannot have more than 2.1GB worth of terms
  66. in a single segment.
  67. This postings format offers the following parameters:
  68. `min_skip_count`::
  69. The minimum number terms with a shared prefix to
  70. allow a skip pointer to be written. The default is *8*.
  71. `low_freq_cutoff`::
  72. Terms with a lower document frequency use a
  73. single array object representation for postings and positions. The
  74. default is *32*.
  75. Type name: `direct`
  76. [float]
  77. [[memory-postings]]
  78. ==== Memory postings format
  79. A postings format that stores terms & postings (docs, positions,
  80. payloads) in RAM, using an FST. This postings format does write to disk,
  81. but loads everything into memory. The memory postings format has the
  82. following options:
  83. `pack_fst`::
  84. A boolean option that defines if the in memory structure
  85. should be packed once its build. Packed will reduce the size for the
  86. data-structure in memory but requires more memory during building.
  87. Default is *false*.
  88. `acceptable_overhead_ratio`::
  89. The compression ratio specified as a
  90. float, that is used to compress internal structures. Example ratios `0`
  91. (Compact, no memory overhead at all, but the returned implementation may
  92. be slow), `0.5` (Fast, at most 50% memory overhead, always select a
  93. reasonably fast implementation), `7` (Fastest, at most 700% memory
  94. overhead, no compression). Default is `0.2`.
  95. Type name: `memory`
  96. [float]
  97. [[bloom-postings]]
  98. ==== Bloom filter posting format
  99. The bloom filter postings format wraps a delegate postings format and on
  100. top of this creates a bloom filter that is written to disk. During
  101. opening this bloom filter is loaded into memory and used to offer
  102. "fast-fail" reads. This postings format is useful for low doc-frequency
  103. fields such as primary keys. The bloom filter postings format has the
  104. following options:
  105. `delegate`::
  106. The name of the configured postings format that the
  107. bloom filter postings format will wrap.
  108. `fpp`::
  109. The desired false positive probability specified as a
  110. floating point number between 0 and 1.0. The `fpp` can be configured for
  111. multiple expected insertions. Example expression: *10k=0.01,1m=0.03*. If
  112. number docs per index segment is larger than *1m* then use *0.03* as fpp
  113. and if number of docs per segment is larger than *10k* use *0.01* as
  114. fpp. The last fallback value is always *0.03*. This example expression
  115. is also the default.
  116. Type name: `bloom`
  117. [float]
  118. [[pulsing-postings]]
  119. ==== Pulsing postings format
  120. The pulsing implementation in-lines the posting lists for very low
  121. frequent terms in the term dictionary. This is useful to improve lookup
  122. performance for low-frequent terms. This postings format offers the
  123. following parameters:
  124. `min_block_size`::
  125. The minimum block size the default Lucene term
  126. dictionary uses to encode on-disk blocks. Defaults to *25*.
  127. `max_block_size`::
  128. The maximum block size the default Lucene term
  129. dictionary uses to encode on-disk blocks. Defaults to *48*.
  130. `freq_cut_off`::
  131. The document frequency cut off where pulsing
  132. in-lines posting lists into the term dictionary. Terms with a document
  133. frequency less or equal to the cutoff will be in-lined. The default is
  134. *1*.
  135. Type name: `pulsing`
  136. [float]
  137. [[default-postings]]
  138. ==== Default postings format
  139. The default postings format has the following options:
  140. `min_block_size`::
  141. The minimum block size the default Lucene term
  142. dictionary uses to encode on-disk blocks. Defaults to *25*.
  143. `max_block_size`::
  144. The maximum block size the default Lucene term
  145. dictionary uses to encode on-disk blocks. Defaults to *48*.
  146. Type name: `default`
  147. [float]
  148. === Configuring a custom doc values format
  149. Custom doc values format can be defined in the index settings in the
  150. `codec` part. The `codec` part can be configured when creating an index
  151. or updating index settings. An example on how to define your custom
  152. doc values format:
  153. [source,js]
  154. --------------------------------------------------
  155. curl -XPUT 'http://localhost:9200/twitter/' -d '{
  156. "settings" : {
  157. "index" : {
  158. "codec" : {
  159. "doc_values_format" : {
  160. "my_format" : {
  161. "type" : "disk"
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }'
  168. --------------------------------------------------
  169. Then we defining your mapping your can use the `my_format` name in the
  170. `doc_values_format` option as the example below illustrates:
  171. [source,js]
  172. --------------------------------------------------
  173. {
  174. "product" : {
  175. "properties" : {
  176. "price" : {"type" : "integer", "doc_values_format" : "my_format"}
  177. }
  178. }
  179. }
  180. --------------------------------------------------
  181. [float]
  182. === Available doc values formats
  183. [float]
  184. ==== Memory doc values format
  185. A doc values format that stores all values in a FST in RAM. This format does
  186. write to disk but the whole data-structure is loaded into memory when reading
  187. the index. The memory postings format has no options.
  188. Type name: `memory`
  189. [float]
  190. ==== Disk doc values format
  191. A doc values format that stores and reads everything from disk. Although it may
  192. be slightly slower than the default doc values format, this doc values format
  193. will require almost no memory from the JVM. The disk doc values format has no
  194. options.
  195. Type name: `disk`
  196. [float]
  197. ==== Default doc values format
  198. The default doc values format tries to make a good compromise between speed and
  199. memory usage by only loading into memory data-structures that matter for
  200. performance. This makes this doc values format a good fit for most use-cases.
  201. The default doc values format has no options.
  202. Type name: `default`