# When to use \_forcemerge?

**URL:** <https://discuss.elastic.co/t/when-to-use-forcemerge/128986>\
**Category:** Elasticsearch\
**Created:** [April 22, 2018, 3:34am UTC](https://discuss.elastic.co/t/when-to-use-forcemerge/128986 "2018-04-22T03:34:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shshnk28](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@shshnk28](https://discuss.elastic.co/u/shshnk28)\
**Post date:** [April 22, 2018, 3:34am UTC](https://discuss.elastic.co/t/when-to-use-forcemerge/128986/1 "2018-04-22T03:34:30Z")

</div>

As per the elasticsearch documentation the segment merging is background process that keeps running. So my question is that in what cases is this segment merging insufficient so that I need to run forcemerge via the API ?  
We have been running forcemerge in our ES cluster periodically since sometime and we see about 10-20% reduction (from 50 GB to 40GB) in our shard size after running forcemerge.

Also is it recommended to run forcemerge on indices which are being actively written to?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 22, 2018, 5:47am UTC](https://discuss.elastic.co/t/when-to-use-forcemerge/128986/2 "2018-04-22T05:47:02Z")

</div>

> [@shshnk28](#):
>
> Also is it recommended to run forcemerge on indices which are being actively written to?

No. It's not recommended.

---

<div class="post-metadata">

**Author:** ![shshnk28](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@shshnk28](https://discuss.elastic.co/u/shshnk28)\
**Post date:** [April 22, 2018, 5:49am UTC](https://discuss.elastic.co/t/when-to-use-forcemerge/128986/3 "2018-04-22T05:49:12Z")

</div>

Can you let me know the reason behind it ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 22, 2018, 6:15am UTC](https://discuss.elastic.co/t/when-to-use-forcemerge/128986/4 "2018-04-22T06:15:29Z")

</div>

You'll end up using much more IO than needed IMO. Elasticsearch/Lucene have good default values. I'd not really call this API.

---

<div class="post-metadata">

**Author:** ![rcowart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rcowart/32/88091_2.png) [@rcowart](https://discuss.elastic.co/u/rcowart)\
**Post date:** [April 22, 2018, 8:28am UTC](https://discuss.elastic.co/t/when-to-use-forcemerge/128986/5 "2018-04-22T08:28:40Z")

</div>

You only want to use \_forcemerge on indices which are no longer being written to, for reasons @dadoonet mentions.

The segments add overhead at both the Elasticsearch and the OS level (excessive file handles, etc.). While merges will run as data is being written, it is not to the level that can be achieved once an index is stable (no more writes). I have seen clusters that were seeing a lot of shard read errors, which were "fixed" by running \_forcemerge on the older indices, freeing resources.

So if you are writing daily, weekly or monthly indices, it is a good idea to issue a \_forcemerge after they are stable. This can be automated using curator.

> NOTE: Keep in mind that \_forcemerge will generate a significant burst of writes that might last for a few seconds or many minutes depending on the size of the index. You must have some write IOPS headroom under normal load or a \_forcemerge will negatively impact the clusters ability to keep up with the ingestion of new data. That said, if you are too close to your IOPS limits to run \_forcemerge, you probably are in need of adding some nodes, or migrating to better storage anyway.

---

<div class="post-metadata">

**Author:** ![shshnk28](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@shshnk28](https://discuss.elastic.co/u/shshnk28)\
**Post date:** [April 22, 2018, 3:04pm UTC](https://discuss.elastic.co/t/when-to-use-forcemerge/128986/6 "2018-04-22T15:04:07Z")

</div>

Thanks for your response @rcowart. Also is there a case when I would need to use focemerge on an index that is not being written to ?  
I believe the background merge job run by ES does the same job as \_forcemerge. So in what cases \_forcemerge provides benefits as compared to the normal background merge process.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 22, 2018, 4:33pm UTC](https://discuss.elastic.co/t/when-to-use-forcemerge/128986/7 "2018-04-22T16:33:26Z")

</div>

With forcemerge you can down to 1 unique segment which will not happen with "normal" merge.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 20, 2018, 4:33pm UTC](https://discuss.elastic.co/t/when-to-use-forcemerge/128986/8 "2018-05-20T16:33:37Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
