How does segment merging work


(None) #1

So i read the docs, but just curious...

Using ES 1.6.0

I had an index with: 257,947,981 documents and it was 1.28TB
Then I did some bulk updates to that index which ended up being: 257,997,034 docs and 1.56TB

Then for sh*ts and giggles I ran POST /my-index/_optimize?max_num_segments=1

Now running the optimize API the index size has grown to 1.7TB
Each shard is about 60 segments each except one is at 40.

Will this really reduces all shards to 1 segments or best it can?
Also will this eventually end up saving space?
And how long should I expect this to execute?


(Mark Walkom) #2

An index won't grow in size if you optimise, it removes any deleted docs and then merges the segments. I'd say there was more indexing happening at the same time.

An optimise will take as long as it takes, it's dependant on the size of the index, load on the system, IO speeds etc etc.


(None) #3

I did the test. I only optimized after bulk updates finished.

Index at start was 1.28TB
Index after updates: 1.56TB
Index while optimizing expanded to 2+TB
Index after optimizing finished: 1.25TB

Now running optimize on none updated index. I.e: No new inserts or updates.


(None) #4

Yep even on a non updated index there's expansion going on.

It started at 1.30TB
Now during optimization it's up to 1.37TB and growing...

I guess it expands when the new segments is created so the old one can get merged into it?


(Mark Walkom) #5

Initially, yes, but it will drop back down.


(None) #6

Cool, I can confirm it. During optimization it expands and then drops back to original size about slightly less.


(system) #7