# Index optimization fails to merge all segments

**URL:** <https://discuss.elastic.co/t/index-optimization-fails-to-merge-all-segments/50984>\
**Category:** Elasticsearch\
**Created:** [May 25, 2016, 8:29pm UTC](https://discuss.elastic.co/t/index-optimization-fails-to-merge-all-segments/50984 "2016-05-25T20:29:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alont](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@alont](https://discuss.elastic.co/u/alont)\
**Post date:** [May 25, 2016, 8:29pm UTC](https://discuss.elastic.co/t/index-optimization-fails-to-merge-all-segments/50984/1 "2016-05-25T20:29:01Z")

</div>

Hello all,

We are running a production Elasticsearch 1.7.4 cluster with time-based data sitting in monthly indexes.

Indexes with data from previous months are very static and don't get written to, so we've decided to optimize them.

We ran the optimization on several indexs with default merge settings and the following optimize request parameters:

> max\_num\_segments = 1  
> flush = true

Immediately after sending the API request, we get this response:

> {"\_shards":{"total":70,"successful":70,"failed":0}}

instead of getting blocked as expected.

After the request is sent, we can see merges start to occur, and the deleted documents count starts declining. Eventually the merges stop but the deleted documents count is still far greater than 0, and there are still hundreds if not thousands of segments in the index.

We've also noticed that sometimes another optimize request is necessary for the disk space to actually be cleared.

Is there something that we're missing? Why is optimize behaving unexpectedly?

Thanks for your help,  
Alon

---

<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:** [May 26, 2016, 3:43am UTC](https://discuss.elastic.co/t/index-optimization-fails-to-merge-all-segments/50984/2 "2016-05-26T03:43:04Z")

</div>

Are you writing to this index while the optimise is happening?

---

<div class="post-metadata">

**Author:** ![ronsher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronsher/32/1334_2.png) [@ronsher](https://discuss.elastic.co/u/ronsher)\
**Post date:** [May 26, 2016, 4:14am UTC](https://discuss.elastic.co/t/index-optimization-fails-to-merge-all-segments/50984/3 "2016-05-26T04:14:09Z")

</div>

No, we don't  
These are "old" indices (previous months)

---

<div class="post-metadata">

**Author:** ![alont](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@alont](https://discuss.elastic.co/u/alont)\
**Post date:** [May 31, 2016, 6:25pm UTC](https://discuss.elastic.co/t/index-optimization-fails-to-merge-all-segments/50984/4 "2016-05-31T18:25:43Z")

</div>

We've resorted to reindexing since nothing seems to fix the issues I've raised in the original post. If anyone has any ideas or suggestions to resolve our issue, they would be greatly appreciated.

---

<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:** [July 5, 2017, 10:47pm UTC](https://discuss.elastic.co/t/index-optimization-fails-to-merge-all-segments/50984/5 "2017-07-05T22:47:35Z")

</div>


