# Merge not starting automatically

**URL:** <https://discuss.elastic.co/t/merge-not-starting-automatically/163408>\
**Category:** Elasticsearch\
**Created:** [January 8, 2019, 4:58pm UTC](https://discuss.elastic.co/t/merge-not-starting-automatically/163408 "2019-01-08T16:58:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matteo\_Grolla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matteo_grolla/32/48451_2.png) [@Matteo\_Grolla](https://discuss.elastic.co/u/Matteo_Grolla)\
**Post date:** [January 8, 2019, 4:58pm UTC](https://discuss.elastic.co/t/merge-not-starting-automatically/163408/1 "2019-01-08T16:58:14Z")

</div>

Hi all!  
I'm using ES 5.3  
and I have an index with 800k docs ~16GB of data  
I deleted ~500k docs and refreshed the index  
cpus and disks are not under load

I expected a merge to happen  
but after several minutes (20 mins) nothing was happening

launching  
POST /\_forcemerge?only\_expunge\_deletes=true

triggered the merge and eventually space was released from disk

merge settings are all default values  
Can anyone explain me why ES does not try to do the merge automatically?

when does ES check if segments need merging?  
does it do it after write operations?  
does it checks periodically?  
there are many indexes in the cluster: ~180  
could this be impact the triggering of the merge?

thank you very much

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 9, 2019, 8:56am UTC](https://discuss.elastic.co/t/merge-not-starting-automatically/163408/2 "2019-01-09T08:56:40Z")

</div>

Elasticsearch (more exactly, Lucene) has something called a merge policy, which takes several factors into account when merging, like the number of segments, their size, the percentage of deleted documents per segment until it decides a merge needs to happen automatically in the background.

if you want to know more about this, you should check out the tiered merge policy.

Hope this helps!

--Alex

---

<div class="post-metadata">

**Author:** ![Matteo\_Grolla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matteo_grolla/32/48451_2.png) [@Matteo\_Grolla](https://discuss.elastic.co/u/Matteo_Grolla)\
**Post date:** [January 9, 2019, 9:12am UTC](https://discuss.elastic.co/t/merge-not-starting-automatically/163408/3 "2019-01-09T09:12:10Z")

</div>

Hi Alex,  
I'm confident with TieredMerge Policy and worked a lot with Solr.  
I called  
POST /\_forcemerge?only\_expunge\_deletes=true

without specifying  
max\_num\_segments

so, as documented in  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.3/indices-forcemerge.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/indices-forcemerge.html)

a merge would only happed if needed (as deemed appropriate by TieredMergePolicy)  
As specified on the original question, the problem is not that the merge is not needed.  
Rather it seems that a check to see if a merge is needed is not performed automatically

I'd like to have a better understanding of when this check is made, can you help me on this?  
Is there any ES configuration related to this?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 9, 2019, 9:38am UTC](https://discuss.elastic.co/t/merge-not-starting-automatically/163408/4 "2019-01-09T09:38:08Z")

</div>

This is all in Lucene Land, on top of my head you need to look at the IndexWriterConfig merge policy. This one gets applied whenever segments are changed (added or via previous merges). The `MergePolicy` is the class in question IIRC

---

<div class="post-metadata">

**Author:** ![Matteo\_Grolla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matteo_grolla/32/48451_2.png) [@Matteo\_Grolla](https://discuss.elastic.co/u/Matteo_Grolla)\
**Post date:** [January 9, 2019, 9:44am UTC](https://discuss.elastic.co/t/merge-not-starting-automatically/163408/5 "2019-01-09T09:44:23Z")

</div>

Thank you very much Alexander!

---

<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:** [February 6, 2019, 9:44am UTC](https://discuss.elastic.co/t/merge-not-starting-automatically/163408/6 "2019-02-06T09:44:26Z")

</div>

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