# \_forcemerge not doing anything

**URL:** <https://discuss.elastic.co/t/forcemerge-not-doing-anything/232310>\
**Category:** Elasticsearch\
**Created:** [May 12, 2020, 7:49pm UTC](https://discuss.elastic.co/t/forcemerge-not-doing-anything/232310 "2020-05-12T19:49:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrossmann](https://avatars.discourse-cdn.com/v4/letter/w/91b2a8/32.png) [@wrossmann](https://discuss.elastic.co/u/wrossmann)\
**Post date:** [May 12, 2020, 7:49pm UTC](https://discuss.elastic.co/t/forcemerge-not-doing-anything/232310/1 "2020-05-12T19:49:09Z")

</div>

I recently had a process go a bit nuts and add a lot of junk documents to some of my indices. It's not the first time that this has happened, and I have a cleanup script that runs `/_delete_by_query` and then `_forcemerge?only_expunge_deletes=true`.

My process is to first pull a copy of the index to a test machine, ensure that the delete/merge works as expected, and then run the process against the production ES cluster. The deletes work, but the forcemerge returns immediately and doesn't do anything. Eg:

```auto
+ curl -s -X POST 'http://localhost:9200/index_name/_forcemerge?only_expunge_deletes=true&pretty'
{
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  }
}

```

and I get the same result if I specify `max_num_segments` as well.

How can I get this forcemerge to work or otherwise purge these documents?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [May 12, 2020, 8:06pm UTC](https://discuss.elastic.co/t/forcemerge-not-doing-anything/232310/2 "2020-05-12T20:06:59Z")

</div>

Usually if force merge doesn't do anything it's because it's not worth doing anything. You can normally rely on Elasticsearch to merge things as it sees fit so there's no need to explicitly force merge as you're doing. It shouldn't matter too much if there's a few deleted documents in the index.

---

<div class="post-metadata">

**Author:** ![wrossmann](https://avatars.discourse-cdn.com/v4/letter/w/91b2a8/32.png) [@wrossmann](https://discuss.elastic.co/u/wrossmann)\
**Post date:** [May 12, 2020, 8:25pm UTC](https://discuss.elastic.co/t/forcemerge-not-doing-anything/232310/3 "2020-05-12T20:25:44Z")

</div>

Well this site seems to be an excellent rubber duck, because the first thing I did after submitting this post was re-read the `_forcemerge` docs where I finally noticed the note:

> This parameter does **not** override the `index.merge.policy.expunge_deletes_allowed` setting.

There's no explicit policy set on the index, and I had to dig up the default from non-official sources since it doesn't seem to be documented outside of the source code, which is 10%. In my case the documents deleted only accounted for 5% of the document count, but are themselves quite oversized.

I ran the following to change the policy for this index:

```auto
curl -X PUT 'http://localhost:9200/index_name/_settings' \
  -H 'Content-Type: application/json' \
  -d '{"index":{"merge":{"policy":{"expunge_deletes_allowed": 0}}}}'

```

After that the forcemerge has run as expected.

---

<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:** [June 9, 2020, 8:25pm UTC](https://discuss.elastic.co/t/forcemerge-not-doing-anything/232310/4 "2020-06-09T20:25:49Z")

</div>

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