Search code examples
lucenelucene.net

What is the difference between commit and flush for IndexWriter in Lucene


What is the difference between commit and flush for IndexWriter in Lucene?

Here is the documentation for the class but it is unclear to me what is the difference between the 2 methods is:

https://lucene.apache.org/core/4_5_0/core/org/apache/lucene/index/IndexWriter.html


Solution

  • Both commit and flush write indexing data that is currently in memory to disk. Commit, however, does something extra. It also updates the index, indicating that the data on disk is ready to be used for searching.

    So if you always flush but never commit, your index can't be searched. If you always commit, but never flush, that is fine since a commit implicitly flushes. Flushing normally occurs automatically when you index a large amount of data that wouldn't be feasible to keep in memory. You only commit when you have reached a state that you want to really persist.