Web / Apache Lucene Interview questions
How does the inverted index handle updates and deletes?
Because Lucene segments are immutable once written, there's no in-place editing of a document's terms. Instead, both updates and deletes work around that immutability:
- Delete - the document is flagged in the segment's live-docs bitset; its postings entries stay physically on disk but are skipped during search and eventually purged when that segment is merged.
- Update - internally implemented as a delete of the old document followed by indexing a brand-new document (often in a new segment) with the same identifying term.
This means index size can temporarily grow after heavy update traffic, since old, deleted-but-not-yet-merged copies still occupy space. Regular background merging is what actually reclaims that space over time.
More Related questions...