Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 374
gus3001 Avatar asked Feb 01 '18 07:02

gus3001


1 Answers

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 cant 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.

like image 115
gus3001 Avatar answered Oct 09 '22 13:10

gus3001