forcemerge.asciidoc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. Multi-index operations are executed one shard at a
  53. time per node. Force merge makes the storage for the shard being merged
  54. temporarily increase, up to double its size in case `max_num_segments` parameter
  55. is set to `1`, as all segments need to be rewritten into a new one.
  56. [[forcemerge-api-path-params]]
  57. ==== {api-path-parms-title}
  58. `<target>`::
  59. (Optional, string)
  60. Comma-separated list of data streams, indices, and index aliases used to limit
  61. the request. Wildcard expressions (`*`) are supported.
  62. +
  63. To target all data streams and indices in a cluster, omit this parameter or use
  64. `_all` or `*`.
  65. [[forcemerge-api-query-params]]
  66. ==== {api-query-parms-title}
  67. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  68. +
  69. Defaults to `true`.
  70. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  71. +
  72. Defaults to `open`.
  73. `flush`::
  74. (Optional, Boolean)
  75. If `true`,
  76. {es} performs a <<indices-flush,flush>> on the indices
  77. after the force merge.
  78. Defaults to `true`.
  79. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  80. `max_num_segments`::
  81. +
  82. --
  83. (Optional, integer)
  84. The number of segments to merge to.
  85. To fully merge indices,
  86. set it to `1`.
  87. Defaults to checking if a merge needs to execute.
  88. If so, executes it.
  89. --
  90. `only_expunge_deletes`::
  91. +
  92. --
  93. (Optional, Boolean)
  94. If `true`,
  95. only expunge segments containing document deletions.
  96. Defaults to `false`.
  97. In Lucene,
  98. a document is not deleted from a segment;
  99. just marked as deleted.
  100. During a merge,
  101. a new segment is created
  102. that does not contain those document deletions.
  103. NOTE: This parameter does *not* override the
  104. `index.merge.policy.expunge_deletes_allowed` setting.
  105. --
  106. [[forcemerge-api-example]]
  107. ==== {api-examples-title}
  108. [[forcemerge-api-specific-ex]]
  109. ===== Force merge a specific data stream or index
  110. [source,console]
  111. ----
  112. POST /my-index-000001/_forcemerge
  113. ----
  114. // TEST[continued]
  115. [[forcemerge-api-multiple-ex]]
  116. ===== Force merge several data streams or indices
  117. [source,console]
  118. ----
  119. POST /my-index-000001,my-index-000002/_forcemerge
  120. ----
  121. // TEST[s/^/PUT my-index-000001\nPUT my-index-000002\n/]
  122. [[forcemerge-api-all-ex]]
  123. ===== Force merge all indices
  124. [source,console]
  125. ----
  126. POST /_forcemerge
  127. ----
  128. [[forcemerge-api-time-based-index-ex]]
  129. ===== Data streams and time-based indices
  130. Force-merging is useful for managing a data stream's older backing indices and
  131. other time-based indices, particularly after a
  132. <<indices-rollover-index,rollover>>.
  133. In these cases,
  134. each index only receives indexing traffic for a certain period of time.
  135. Once an index receive no more writes,
  136. its shards can be force-merged to a single segment.
  137. [source,console]
  138. --------------------------------------------------
  139. POST /.ds-my-data-stream-2099.03.07-000001/_forcemerge?max_num_segments=1
  140. --------------------------------------------------
  141. // TEST[setup:my_index]
  142. // TEST[s/.ds-my-data-stream-2099.03.07-000001/my-index-000001/]
  143. This can be a good idea because single-segment shards can sometimes use simpler
  144. and more efficient data structures to perform searches.