forcemerge.asciidoc 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. [[indices-forcemerge]]
  2. === Force Merge
  3. The force merge API allows you to force a <<index-modules-merge,merge>> on the
  4. shards of one or more indices. Merging reduces the number of segments in each
  5. shard by merging some of them together, and also frees up the space used by
  6. deleted documents. Merging normally happens automatically, but sometimes it is
  7. useful to trigger a merge manually.
  8. WARNING: **Force merge should only be called against an index after you have
  9. finished writing to it.** Force merge can cause very large (>5GB) segments to
  10. be produced, and if you continue to write to such an index then the automatic
  11. merge policy will never consider these segments for future merges until they
  12. mostly consist of deleted documents. This can cause very large segments to
  13. remain in the index which can result in increased disk usage and worse search
  14. performance.
  15. Calls to this API block until the merge is complete. If the client connection
  16. is lost before completion then the force merge process will continue in the
  17. background. Any new requests to force merge the same indices will also block
  18. until the ongoing force merge is complete.
  19. [source,js]
  20. --------------------------------------------------
  21. POST /twitter/_forcemerge
  22. --------------------------------------------------
  23. // CONSOLE
  24. // TEST[setup:twitter]
  25. Force-merging can be useful with time-based indices and when using
  26. <<indices-rollover-index,rollover>>. In these cases each index only receives
  27. indexing traffic for a certain period of time, and once an index will receive
  28. no more writes its shards can be force-merged down to a single segment:
  29. [source,js]
  30. --------------------------------------------------
  31. POST /logs-000001/_forcemerge?max_num_segments=1
  32. --------------------------------------------------
  33. // CONSOLE
  34. // TEST[setup:twitter]
  35. // TEST[s/logs-000001/twitter/]
  36. This can be a good idea because single-segment shards can sometimes use simpler
  37. and more efficient data structures to perform searches.
  38. [float]
  39. [[forcemerge-parameters]]
  40. ==== Request Parameters
  41. The force merge API accepts the following request parameters:
  42. [horizontal]
  43. `max_num_segments`:: The number of segments to merge to. To fully
  44. merge the index, set it to `1`. Defaults to simply checking if a
  45. merge needs to execute, and if so, executes it.
  46. `only_expunge_deletes`:: Should the merge process only expunge segments with
  47. deletes in it. In Lucene, a document is not deleted from a segment, just marked
  48. as deleted. During a merge process of segments, a new segment is created that
  49. does not have those deletes. This flag allows to only merge segments that have
  50. deletes. Defaults to `false`. Note that this won't override the
  51. `index.merge.policy.expunge_deletes_allowed` threshold.
  52. `flush`:: Should a flush be performed after the forced merge. Defaults to
  53. `true`.
  54. [source,js]
  55. --------------------------------------------------
  56. POST /kimchy/_forcemerge?only_expunge_deletes=false&max_num_segments=100&flush=true
  57. --------------------------------------------------
  58. // CONSOLE
  59. // TEST[s/^/PUT kimchy\n/]
  60. [float]
  61. [[forcemerge-multi-index]]
  62. ==== Multi Index
  63. The force merge API can be applied to more than one index with a single call, or
  64. even on `_all` the indices. Multi index operations are executed one shard at a
  65. time per node. Force merge makes the storage for the shard being merged
  66. temporarily increase, up to double its size in case `max_num_segments` is set
  67. to `1`, as all segments need to be rewritten into a new one.
  68. [source,js]
  69. --------------------------------------------------
  70. POST /kimchy,elasticsearch/_forcemerge
  71. POST /_forcemerge
  72. --------------------------------------------------
  73. // CONSOLE
  74. // TEST[s/^/PUT kimchy\nPUT elasticsearch\n/]