# Safe usage of \`\_forcemerge\` with \`only\_expunge\_deletes\`

**URL:** <https://discuss.elastic.co/t/safe-usage-of-forcemerge-with-only-expunge-deletes/321964>\
**Category:** Elasticsearch\
**Created:** [December 25, 2022, 10:31am UTC](https://discuss.elastic.co/t/safe-usage-of-forcemerge-with-only-expunge-deletes/321964 "2022-12-25T10:31:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Au6ojlut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/au6ojlut/32/115222_2.png) [@Au6ojlut](https://discuss.elastic.co/u/Au6ojlut)\
**Post date:** [December 25, 2022, 10:31am UTC](https://discuss.elastic.co/t/safe-usage-of-forcemerge-with-only-expunge-deletes/321964/1 "2022-12-25T10:31:37Z")

</div>

Hello Team

I am using the Elasticsearch 8.4.2.

I have several indices, that is receiving updates (or deletes). On some indices update operation goes with the [optimistic-concurrency-control](https://www.elastic.co/guide/en/elasticsearch/reference/current/optimistic-concurrency-control.html).

After some time, when the percent of deleted document goes a bit higher then 30, the update query performance degrades. The update operations, that usually executes fast enough (99 percentile is under `100ms`) suddenly start respond in `1sec` or more.

For now I use `cron` to execute the `_forcemerge` with `only_expunge_deletes` flag during the night. It helps to keep responses under `100ms`, but I am worry about this

> We recommend only force merging a read-only index (meaning the index is no longer receiving writes). When documents are updated or deleted, the old version is not immediately removed, but instead soft-deleted and marked with a "tombstone". These soft-deleted documents are automatically cleaned up during regular segment merges. But force merge can cause very large (\> 5GB) segments to be produced, which are not eligible for regular merges. So the number of soft-deleted documents can then grow rapidly, resulting in higher disk usage and worse search performance. If you regularly force merge an index receiving writes, this can also make snapshots more expensive, since the new documents can’t be backed up incrementally.

According to the lucene java doc:  
[https://lucene.apache.org/core/9\_0\_0/core/org/apache/lucene/index/TieredMergePolicy.html](https://lucene.apache.org/core/9_0_0/core/org/apache/lucene/index/TieredMergePolicy.html)

> findForcedDeletesMerges should never produce segments greater than maxSegmentSize.

and also to this change in elastic:  
[More optimal forced merges when max\_num\_segments is greater than 1](https://github.com/elastic/elasticsearch/pull/85065)

if I understand everything correctly, it's safe to call `_forcemerge` with `only_expunge_deletes` flag and I shouldn't worry about the huge segments appearance on indices that continue receiving index or update operations?

---

<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:** [January 22, 2023, 10:32am UTC](https://discuss.elastic.co/t/safe-usage-of-forcemerge-with-only-expunge-deletes/321964/2 "2023-01-22T10:32:32Z")

</div>

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