1
1
[[indices-forcemerge]]
2
2
=== Force Merge
3
3
4
- The force merge API allows to force merging of one or more indices through an
5
- API. The merge relates to the number of segments a Lucene index holds within
6
- each shard. The force merge operation allows to reduce the number of segments by
7
- merging them.
4
+ The force merge API allows you to force a <<index-modules-merge,merge>> on the
5
+ shards of one or more indices. Merging reduces the number of segments in each
6
+ shard by merging some of them together, and also frees up the space used by
7
+ deleted documents. Merging normally happens automatically, but sometimes it is
8
+ useful to trigger a merge manually.
8
9
9
- This call will block until the merge is complete. If the http connection is
10
- lost, the request will continue in the background, and any new requests will
11
- block until the previous force merge is complete.
10
+ WARNING: **Force merge should only be called against an index after you have
11
+ finished writing to it.** Force merge can cause very large (>5GB) segments to
12
+ be produced, and if you continue to write to such an index then the automatic
13
+ merge policy will never consider these segments for future merges until they
14
+ mostly consist of deleted documents. This can cause very large segments to
15
+ remain in the index which can result in increased disk usage and worse search
16
+ performance.
12
17
13
- WARNING: Force merge should only be called against *read-only indices*. Running
14
- force merge against a read-write index can cause very large segments to be produced
15
- (>5Gb per segment), and the merge policy will never consider it for merging again until
16
- it mostly consists of deleted docs. This can cause very large segments to remain in the shards .
18
+ Calls to this API block until the merge is complete. If the client connection
19
+ is lost before completion then the force merge process will continue in the
20
+ background. Any new requests to force merge the same indices will also block
21
+ until the ongoing force merge is complete .
17
22
18
23
[source,js]
19
24
--------------------------------------------------
@@ -22,6 +27,22 @@ POST /twitter/_forcemerge
22
27
// CONSOLE
23
28
// TEST[setup:twitter]
24
29
30
+ Force-merging can be useful with time-based indices and when using
31
+ <<indices-rollover-index,rollover>>. In these cases each index only receives
32
+ indexing traffic for a certain period of time, and once an index will receive
33
+ no more writes its shards can be force-merged down to a single segment:
34
+
35
+ [source,js]
36
+ --------------------------------------------------
37
+ POST /logs-000001/_forcemerge?max_num_segments=1
38
+ --------------------------------------------------
39
+ // CONSOLE
40
+ // TEST[setup:twitter]
41
+ // TEST[s/logs-000001/twitter/]
42
+
43
+ This can be a good idea because single-segment shards can sometimes use simpler
44
+ and more efficient data structures to perform searches.
45
+
25
46
[float]
26
47
[[forcemerge-parameters]]
27
48
==== Request Parameters
0 commit comments