forcemerge.asciidoc 4.9 KB

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