I have a large Solr search index, with many segments. I want to merge them to consume less space on the disk and speed up the search by scanning a smaller index, by removing deleted documents form the search during the segment merge.
The default behavior of optimize is that all segments are merged until only one segment is left. I want to avoid that and stop earlier with a specified number of segments left. Otherwise the merge might fail with an out of memory exception, while trying to merge two chunks which are together larger than the available RAM.