forcemerge.asciidoc 5.2 KB

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