# Es forcemerge question

**URL:** <https://discuss.elastic.co/t/es-forcemerge-question/247467>\
**Category:** Elasticsearch\
**Created:** [September 4, 2020, 1:49am UTC](https://discuss.elastic.co/t/es-forcemerge-question/247467 "2020-09-04T01:49:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![taidengpub](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/taidengpub/32/75088_2.png) [@taidengpub](https://discuss.elastic.co/u/taidengpub)\
**Post date:** [September 4, 2020, 1:49am UTC](https://discuss.elastic.co/t/es-forcemerge-question/247467/1 "2020-09-04T01:49:04Z")

</div>

i use ilm to run forcemerge with max\_num\_segments=5 and this index have 5shard a one replication,so it have 10 shards total

```auto
      "warm": {
                "min_age": "25h",
                "actions": {
                    "forcemerge": {
                        "max_num_segments": 5
                    }
                }
            },

```

when i finshed it  
\_cat/indices see below

```auto
h s idx segmentsCount p r docsCount docsDeleted storeSize pri.store.size fielddataMemory getExistsTotal memoryTotal mergesCurrent mergesTotal mergesCurrentDocs mergesCurrentSize flushTotal refreshTotal
green open xxx 97 5 1 1029288 0 798.3gb 406.4gb 0b 2906 7.8mb 0 115 0 0b 273 20

```

you can see it has 97 segmentsCount more than 50  
when i run /\_refresh, i get below ,it change to 50 ,is it a es bug???

```auto
h s idx segmentsCount p r docsCount docsDeleted storeSize pri.store.size fielddataMemory getExistsTotal memoryTotal mergesCurrent mergesTotal mergesCurrentDocs mergesCurrentSize flushTotal refreshTotal
green open xxx 50 5 1 1029288 0 783.7gb 391.8gb 0b 2906 7.6mb 0 115 0 0b 273 30

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 4, 2020, 1:59am UTC](https://discuss.elastic.co/t/es-forcemerge-question/247467/2 "2020-09-04T01:59:57Z")

</div>

Are you still writing into this index?

---

<div class="post-metadata">

**Author:** ![taidengpub](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/taidengpub/32/75088_2.png) [@taidengpub](https://discuss.elastic.co/u/taidengpub)\
**Post date:** [September 4, 2020, 2:16am UTC](https://discuss.elastic.co/t/es-forcemerge-question/247467/3 "2020-09-04T02:16:29Z")

</div>

may be still writing some data，but why the segmets reduce immediately after refresh

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 4, 2020, 2:18am UTC](https://discuss.elastic.co/t/es-forcemerge-question/247467/4 "2020-09-04T02:18:32Z")

</div>

I would strongly recommend **against** running a force merge while writing to the index, from [the docs](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/indices-forcemerge.html);

> **Force merge should only be called against an index after you have finished writing to it.** Force merge can cause very large (\>5GB) segments to be produced, and if you continue to write to such an index then the automatic merge policy will never consider these segments for future merges until they mostly consist of deleted documents. This can cause very large segments to remain in the index which can result in increased disk usage and worse search performance.

---

<div class="post-metadata">

**Author:** ![taidengpub](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/taidengpub/32/75088_2.png) [@taidengpub](https://discuss.elastic.co/u/taidengpub)\
**Post date:** [September 4, 2020, 2:29am UTC](https://discuss.elastic.co/t/es-forcemerge-question/247467/5 "2020-09-04T02:29:52Z")

</div>

When executing forcemerge, it is best to ensure that the index is no longer written. I know this.  
Our es index is one index per day . Most real-time data will not be written to yesterday’s index, but the clocks of some clients may not be synchronized, causing some data （few） to be written to yesterday’s index, and yesterday’s index has started to execute forcemerge to optimize the query performance。  
i share part of our ilm settings

```auto
  "hot": {
                "min_age": "0ms",
                "actions": {
                    "set_priority": {
                        "priority": 100
                    }
                }
            },
            "warm": {
                "min_age": "25h",
                "actions": {
                    "forcemerge": {
                        "max_num_segments": 5
                    }
                }
            },
            "cold": {
                "min_age": "28h",
                "actions": {
                    "set_priority": {
                        "priority": 0
                    },
                    "allocate": {
                        "number_of_replicas": 1
                    }
                }
            },

```

thanks，we consider other solutions later。thanks for your reply。

---

<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:** [October 2, 2020, 2:29am UTC](https://discuss.elastic.co/t/es-forcemerge-question/247467/6 "2020-10-02T02:29:55Z")

</div>

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