我使用solrClient.add(SolrInputDocument doc)
方法逐个将文档添加到solr
。
在此之后我明确地呼叫solrClient.commit()
是否需要? ,我看到了一些add
方法,为delay
指定了commit
。
这是什么意思,简单的add
方法在多长时间后没有提交,或者是否提交?
答案 0 :(得分:3)
在Solr中,我们主要有两种不同类型的提交:
硬提交:这由solrconfig.xml中的 autoCommit 选项或来自客户端的显式调用(SolrJ或HTTP通过 浏览器,cURL或类似的)。硬提交会截断当前段 并在索引中打开一个新段。 openSearcher:一个布尔值 子属性控制是否新承诺 数据在后续搜索中可见。
软提交:比硬提交(openSearcher = true)更便宜的操作,也使文档对搜索可见。
上面的文字引自this来源,您可以在其中找到其他信息 添加文档时,不会提交文档,直到上述某个提交发生。 您可以在solrconfig.xml中检查提交选项的默认值。 通常我希望您根据应用程序的需要调整硬和软提交时间,而不是从代码中调用显式提交,除非您需要将条目直接写入磁盘。
更具体地说,如果您更改solrconfig.xml以便以下列方式包含软设置和硬提交设置:
<!-- 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将每30秒自动运行一次softCommit,这将使您的文档每隔10分钟对搜索和硬提交可见。 所以,无论你使用SolrJ添加什么:
solrClient.add(SolrInputDocument doc)
将在30秒后软件提交并在10分钟后提交,而不需要solrClient.commit()调用。