Web / Apache Lucene Interview questions
How does Lucene handle segment merging?
Merging is how Lucene keeps segment count under control and reclaims space from deleted documents, since individual segments are never edited in place. A MergePolicy decides which segments to combine and when, while a MergeScheduler decides how that merge work is actually executed (usually on background threads).
The default TieredMergePolicy groups segments into size-based tiers and prefers merging segments of similar size together, rather than strictly merging in the order they were created like the older LogMergePolicy did. It also factors in the percentage of deleted documents a segment holds, prioritizing merges that reclaim the most wasted space.
Because merges happen in the background while the index stays searchable and writable, the main trade-off applications tune is I/O throttling - ConcurrentMergeScheduler limits how much merge I/O competes with foreground indexing and search traffic.
More Related questions...