forcemerge.asciidoc 4.4 KB

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