merge.asciidoc 8.9 KB

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