forcemerge.asciidoc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. [[indices-forcemerge]]
  2. === Force merge API
  3. ++++
  4. <titleabbrev>Force merge</titleabbrev>
  5. ++++
  6. Forces a <<index-modules-merge,merge>> on the shards of one or more indices.
  7. For data streams, the API forces a merge on the shards of the stream's backing
  8. indices.
  9. [source,console]
  10. ----
  11. POST /my-index-000001/_forcemerge
  12. ----
  13. // TEST[setup:my_index]
  14. [[forcemerge-api-request]]
  15. ==== {api-request-title}
  16. `POST /<target>/_forcemerge`
  17. `POST /_forcemerge`
  18. [[forcemerge-api-prereqs]]
  19. ==== {api-prereq-title}
  20. * If the {es} {security-features} are enabled, you must have the `maintenance`
  21. or `manage` <<privileges-list-indices,index privilege>> for the target data
  22. stream, index, or index alias.
  23. [[forcemerge-api-desc]]
  24. ==== {api-description-title}
  25. Use the force merge API to force a <<index-modules-merge,merge>> on the
  26. shards of one or more indices. Merging reduces the number of segments in each
  27. shard by merging some of them together, and also frees up the space used by
  28. deleted documents. Merging normally happens automatically, but sometimes it is
  29. useful to trigger a merge manually.
  30. // tag::force-merge-read-only-warn[]
  31. WARNING: **Force merge should only be called against an index after you have
  32. finished writing to it.** Force merge can cause very large (>5GB) segments to
  33. be produced, and if you continue to write to such an index then the automatic
  34. merge policy will never consider these segments for future merges until they
  35. mostly consist of deleted documents. This can cause very large segments to
  36. remain in the index which can result in increased disk usage and worse search
  37. performance.
  38. // end::force-merge-read-only-warn[]
  39. [[forcemerge-blocks]]
  40. ===== Blocks during a force merge
  41. Calls to this API block until the merge is complete. If the client connection
  42. is lost before completion then the force merge process will continue in the
  43. background. Any new requests to force merge the same indices will also block
  44. until the ongoing force merge is complete.
  45. [[forcemerge-multi-index]]
  46. ===== Force merging multiple indices
  47. You can force merge multiple indices with a single request by targeting:
  48. * One or more data streams that contain multiple backing indices
  49. * Multiple indices
  50. * One or more index aliases that point to multiple indices
  51. * All data streams and indices in a cluster
  52. Each targeted shard is force-merged separately using <<modules-threadpool,the
  53. `force_merge` threadpool>>. By default each node only has a single
  54. `force_merge` thread which means that the shards on that node are force-merged
  55. one at a time. If you expand the `force_merge` threadpool on a node then it
  56. will force merge its shards in parallel.
  57. Force merge makes the storage for the shard being merged temporarily
  58. increase, up to double its size in case `max_num_segments` parameter is set to
  59. `1`, as all segments need to be rewritten into a new one.
  60. [[forcemerge-api-path-params]]
  61. ==== {api-path-parms-title}
  62. `<target>`::
  63. (Optional, string)
  64. Comma-separated list of data streams, indices, and index aliases used to limit
  65. the request. Wildcard expressions (`*`) are supported.
  66. +
  67. To target all data streams and indices in a cluster, omit this parameter or use
  68. `_all` or `*`.
  69. [[forcemerge-api-query-params]]
  70. ==== {api-query-parms-title}
  71. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  72. +
  73. Defaults to `true`.
  74. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  75. +
  76. Defaults to `open`.
  77. `flush`::
  78. (Optional, Boolean)
  79. If `true`,
  80. {es} performs a <<indices-flush,flush>> on the indices
  81. after the force merge.
  82. Defaults to `true`.
  83. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  84. `max_num_segments`::
  85. +
  86. --
  87. (Optional, integer)
  88. The number of segments to merge to.
  89. To fully merge indices,
  90. set it to `1`.
  91. Defaults to checking if a merge needs to execute.
  92. If so, executes it.
  93. --
  94. `only_expunge_deletes`::
  95. +
  96. --
  97. (Optional, Boolean)
  98. If `true`,
  99. only expunge segments containing document deletions.
  100. Defaults to `false`.
  101. In Lucene,
  102. a document is not deleted from a segment;
  103. just marked as deleted.
  104. During a merge,
  105. a new segment is created
  106. that does not contain those document deletions.
  107. NOTE: This parameter does *not* override the
  108. `index.merge.policy.expunge_deletes_allowed` setting.
  109. --
  110. [[forcemerge-api-example]]
  111. ==== {api-examples-title}
  112. [[forcemerge-api-specific-ex]]
  113. ===== Force merge a specific data stream or index
  114. [source,console]
  115. ----
  116. POST /my-index-000001/_forcemerge
  117. ----
  118. // TEST[continued]
  119. [[forcemerge-api-multiple-ex]]
  120. ===== Force merge several data streams or indices
  121. [source,console]
  122. ----
  123. POST /my-index-000001,my-index-000002/_forcemerge
  124. ----
  125. // TEST[s/^/PUT my-index-000001\nPUT my-index-000002\n/]
  126. [[forcemerge-api-all-ex]]
  127. ===== Force merge all indices
  128. [source,console]
  129. ----
  130. POST /_forcemerge
  131. ----
  132. [[forcemerge-api-time-based-index-ex]]
  133. ===== Data streams and time-based indices
  134. Force-merging is useful for managing a data stream's older backing indices and
  135. other time-based indices, particularly after a
  136. <<indices-rollover-index,rollover>>.
  137. In these cases,
  138. each index only receives indexing traffic for a certain period of time.
  139. Once an index receive no more writes,
  140. its shards can be force-merged to a single segment.
  141. [source,console]
  142. --------------------------------------------------
  143. POST /.ds-my-data-stream-2099.03.07-000001/_forcemerge?max_num_segments=1
  144. --------------------------------------------------
  145. // TEST[setup:my_index]
  146. // TEST[s/.ds-my-data-stream-2099.03.07-000001/my-index-000001/]
  147. This can be a good idea because single-segment shards can sometimes use simpler
  148. and more efficient data structures to perform searches.