merge.asciidoc 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. [[index-modules-merge]]
  2. == Merge
  3. A shard in elasticsearch is a Lucene index, and a Lucene index is broken
  4. down into segments. Segments are internal storage elements in the index
  5. where the index data is stored, and are immutable up to delete markers.
  6. Segments are, periodically, merged into larger segments to keep the
  7. index size at bay and expunge deletes.
  8. The more segments one has in the Lucene index mean slower searches and
  9. more memory used, but, low number of segments means more merging that
  10. has to go on.
  11. Since merges can be expensive to perform, especially on low IO
  12. environments, they can be throttled using store level throttling. Read
  13. the store module documentation on how to set it.
  14. [float]
  15. [[policy]]
  16. === Policy
  17. The index merge policy module allows one to control which segments of a
  18. shard index are to be merged. There are several types of policies with
  19. the default set to `tiered`.
  20. [float]
  21. [[tiered]]
  22. ==== tiered
  23. Merges segments of approximately equal size, subject to an allowed
  24. number of segments per tier. This is similar to `log_bytes_size` merge
  25. policy, except this merge policy is able to merge non-adjacent segment,
  26. and separates how many segments are merged at once from how many
  27. segments are allowed per tier. This merge policy also does not
  28. over-merge (i.e., cascade merges).
  29. This policy has the following settings:
  30. `index.merge.policy.expunge_deletes_allowed`::
  31. When expungeDeletes is called, we only merge away a segment if its delete
  32. percentage is over this threshold. Default is `10`.
  33. `index.merge.policy.floor_segment`::
  34. Segments smaller than this are "rounded up" to this size, i.e. treated as
  35. equal (floor) size for merge selection. This is to prevent frequent
  36. flushing of tiny segments from allowing a long tail in the index. Default
  37. is `2mb`.
  38. `index.merge.policy.max_merge_at_once`::
  39. Maximum number of segments to be merged at a time during "normal" merging.
  40. Default is `10`.
  41. `index.merge.policy.max_merge_at_once_explicit`::
  42. Maximum number of segments to be merged at a time, during optimize or
  43. expungeDeletes. Default is `30`.
  44. `index.merge.policy.max_merged_segment`::
  45. Maximum sized segment to produce during normal merging (not explicit
  46. optimize). This setting is approximate: the estimate of the merged segment
  47. size is made by summing sizes of to-be-merged segments (compensating for
  48. percent deleted docs). Default is `5gb`.
  49. `index.merge.policy.segments_per_tier`::
  50. Sets the allowed number of segments per tier. Smaller values mean more
  51. merging but fewer segments. Default is `10`. Note, this value needs to be
  52. >= then the `max_merge_at_once_` otherwise you'll force too many merges to
  53. occur.
  54. `index.reclaim_deletes_weight`::
  55. Controls how aggressively merges that reclaim more deletions are favored.
  56. Higher values favor selecting merges that reclaim deletions. A value of
  57. `0.0` means deletions don't impact merge selection. Defaults to `2.0`.
  58. `index.compound_format`::
  59. Should the index be stored in compound format or not. Defaults to `false`.
  60. See <<index-compound-format,`index.compound_format`>> in
  61. <<index-modules-settings>>.
  62. For normal merging, this policy first computes a "budget" of how many
  63. segments are allowed by be in the index. If the index is over-budget,
  64. then the policy sorts segments by decreasing size (pro-rating by percent
  65. deletes), and then finds the least-cost merge. Merge cost is measured by
  66. a combination of the "skew" of the merge (size of largest seg divided by
  67. smallest seg), total merge size and pct deletes reclaimed, so that
  68. merges with lower skew, smaller size and those reclaiming more deletes,
  69. are favored.
  70. If a merge will produce a segment that's larger than
  71. `max_merged_segment` then the policy will merge fewer segments (down to
  72. 1 at once, if that one has deletions) to keep the segment size under
  73. budget.
  74. Note, this can mean that for large shards that holds many gigabytes of
  75. data, the default of `max_merged_segment` (`5gb`) can cause for many
  76. segments to be in an index, and causing searches to be slower. Use the
  77. indices segments API to see the segments that an index have, and
  78. possibly either increase the `max_merged_segment` or issue an optimize
  79. call for the index (try and aim to issue it on a low traffic time).
  80. [float]
  81. [[log-byte-size]]
  82. ==== log_byte_size
  83. A merge policy that merges segments into levels of exponentially
  84. increasing *byte size*, where each level has fewer segments than the
  85. value of the merge factor. Whenever extra segments (beyond the merge
  86. factor upper bound) are encountered, all segments within the level are
  87. merged.
  88. This policy has the following settings:
  89. [cols="<,<",options="header",]
  90. |=======================================================================
  91. |Setting |Description
  92. |index.merge.policy.merge_factor |Determines how often segment indices
  93. are merged by index operation. With smaller values, less RAM is used
  94. while indexing, and searches on unoptimized indices are faster, but
  95. indexing speed is slower. With larger values, more RAM is used during
  96. indexing, and while searches on unoptimized indices are slower, indexing
  97. is faster. Thus larger values (greater than 10) are best for batch index
  98. creation, and smaller values (lower than 10) for indices that are
  99. interactively maintained. Defaults to `10`.
  100. |index.merge.policy.min_merge_size |A size setting type which sets the
  101. minimum size for the lowest level segments. Any segments below this size
  102. are considered to be on the same level (even if they vary drastically in
  103. size) and will be merged whenever there are mergeFactor of them. This
  104. effectively truncates the "long tail" of small segments that would
  105. otherwise be created into a single level. If you set this too large, it
  106. could greatly increase the merging cost during indexing (if you flush
  107. many small segments). Defaults to `1.6mb`
  108. |index.merge.policy.max_merge_size |A size setting type which sets the
  109. largest segment (measured by total byte size of the segment's files)
  110. that may be merged with other segments. Defaults to unbounded.
  111. |index.merge.policy.max_merge_docs |Determines the largest segment
  112. (measured by document count) that may be merged with other segments.
  113. Defaults to unbounded.
  114. |=======================================================================
  115. [float]
  116. [[log-doc]]
  117. ==== log_doc
  118. A merge policy that tries to merge segments into levels of exponentially
  119. increasing *document count*, where each level has fewer segments than
  120. the value of the merge factor. Whenever extra segments (beyond the merge
  121. factor upper bound) are encountered, all segments within the level are
  122. merged.
  123. [cols="<,<",options="header",]
  124. |=======================================================================
  125. |Setting |Description
  126. |index.merge.policy.merge_factor |Determines how often segment indices
  127. are merged by index operation. With smaller values, less RAM is used
  128. while indexing, and searches on unoptimized indices are faster, but
  129. indexing speed is slower. With larger values, more RAM is used during
  130. indexing, and while searches on unoptimized indices are slower, indexing
  131. is faster. Thus larger values (greater than 10) are best for batch index
  132. creation, and smaller values (lower than 10) for indices that are
  133. interactively maintained. Defaults to `10`.
  134. |index.merge.policy.min_merge_docs |Sets the minimum size for the lowest
  135. level segments. Any segments below this size are considered to be on the
  136. same level (even if they vary drastically in size) and will be merged
  137. whenever there are mergeFactor of them. This effectively truncates the
  138. "long tail" of small segments that would otherwise be created into a
  139. single level. If you set this too large, it could greatly increase the
  140. merging cost during indexing (if you flush many small segments).
  141. Defaults to `1000`.
  142. |index.merge.policy.max_merge_docs |Determines the largest segment
  143. (measured by document count) that may be merged with other segments.
  144. Defaults to unbounded.
  145. |=======================================================================
  146. [float]
  147. [[scheduling]]
  148. === Scheduling
  149. The merge schedule controls the execution of merge operations once they
  150. are needed (according to the merge policy). The following types are
  151. supported, with the default being the `ConcurrentMergeScheduler`.
  152. [float]
  153. ==== ConcurrentMergeScheduler
  154. A merge scheduler that runs merges using a separated thread, until the
  155. maximum number of threads at which when a merge is needed, the thread(s)
  156. that are updating the index will pause until one or more merges
  157. completes.
  158. The scheduler supports the following settings:
  159. [cols="<,<",options="header",]
  160. |=======================================================================
  161. |Setting |Description
  162. |index.merge.scheduler.max_thread_count |The maximum number of threads
  163. to perform the merge operation. Defaults to
  164. `Math.max(1, Math.min(3, Runtime.getRuntime().availableProcessors() / 2))`.
  165. |=======================================================================
  166. [float]
  167. ==== SerialMergeScheduler
  168. A merge scheduler that simply does each merge sequentially using the
  169. calling thread (blocking the operations that triggered the merge, the
  170. index operation).