merge.asciidoc 9.0 KB

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