I am using the solrClient.add(SolrInputDocument doc)
method to add documents, one by one, to my solr
.
after this i explicitly call solrClient.commit()
Is it required? , I have seen some add
methods, which specify a delay
for commit
.
What does this mean, does the simple add
method does not commit, or if it does, after how long?
In Solr we have mainly two different types of commit:
Hard commit: This is governed by the autoCommit option in solrconfig.xml or explicit calls from a client (SolrJ or HTTP via the
browser, cURL or similar). Hard commits truncate the current segment
and open a new segment in your index. openSearcher: A boolean
sub-property of that governs whether the newly-committed
data is made visible to subsequent searches.
Soft commit: A less-expensive operation than hard-commit (openSearcher=true) that also makes documents visible to search.
Text above is quoted from this source, where you can find additional infos.
When you add a document, that won't be committed until one of the commits above will happen.
You can check in solrconfig.xml what's the default for your commit options.
Normally I would expect you to tune up the hard and soft commit times according your application needs and not to call an explicit commit from your code, unless you need the entry to be written on disk straightaway.
To be more specific, if you change your solrconfig.xml in order to include soft and hardcommit settings in the following way:
<!-- AutoCommit
Perform a hard commit automatically under certain conditions.
Instead of enabling autoCommit, consider using "commitWithin"
when adding documents.
http://wiki.apache.org/solr/UpdateXmlMessages
maxDocs - Maximum number of documents to add since the last
commit before automatically triggering a new commit.
maxTime - Maximum amount of time in ms that is allowed to pass
since a document was added before automatically
triggering a new commit.
openSearcher - if false, the commit causes recent index changes
to be flushed to stable storage, but does not cause a new
searcher to be opened to make those changes visible.
If the updateLog is enabled, then it's highly recommended to
have some sort of hard autoCommit to limit the log size.
-->
<autoCommit>
<maxTime>600000</maxTime>
<openSearcher>false</openSearcher>
</autoCommit>
<!-- softAutoCommit is like autoCommit except it causes a
'soft' commit which only ensures that changes are visible
but does not ensure that data is synced to disk. This is
faster and more near-realtime friendly than a hard commit.
-->
<autoSoftCommit>
<maxTime>30000</maxTime>
</autoSoftCommit>
Solr will run automatically a softCommit every 30 seconds that will make your docs visible to Search and a hard commit every 10 minutes.
So, whatever you added with SolrJ using:
solrClient.add(SolrInputDocument doc)
will be soft committed after 30 seconds and hard committed after 10 minutes without any need for solrClient.commit() call.