Web / Apache Lucene Interview questions
What happens when you call IndexWriter.forceMerge()?
forceMerge() tells Lucene to merge segments down to a target maximum count (often 1) regardless of what the normal MergePolicy would decide on its own. It's the manual override for "consolidate everything now."
Two concrete effects follow from that: first, deleted documents in the merged-away segments are physically purged, reclaiming disk space; second, having fewer, larger segments can speed up read-heavy queries since there's less per-segment overhead to fan out across.
The catch is cost - forceMerge rewrites large amounts of data and is I/O and CPU intensive, so it's best scheduled during low-traffic windows and generally avoided on indexes with continuous, frequent updates, where the normal background MergePolicy is a better fit than repeatedly forcing full consolidation.
More Related questions...