merge.asciidoc 9.0 KB

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