我正在使用solrClient.add(SolrInputDocument doc)
将文档逐一添加到我的方法solr
.
之后我明确地打电话solrClient.commit()
是必须的吗? ,我见过一些add
方法,它指定一个delay
for commit
。
这是什么意思,简单来说add
方法没有提交,或者如果提交了,需要多长时间?
在 Solr 中,我们主要有两种不同类型的提交:
硬提交: 这是由自动提交solrconfig.xml 中的选项或来自客户端的显式调用(SolrJ 或 HTTP 通过
浏览器、cURL 或类似浏览器)。硬提交会截断当前段
并在索引中打开一个新段。 openSearcher:布尔值
的子属性决定新提交的是否
数据对后续搜索可见。
软提交:比硬提交 (openSearcher=true) 更便宜的操作,也使文档对搜索可见。
以上文字引自this https://lucidworks.com/blog/2013/08/23/understanding-transaction-logs-softcommit-and-commit-in-sorlcloud/来源,您可以在其中找到其他信息。
当您添加文档时,只有在发生上述提交之一之后才会提交该文档。
您可以在 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 秒自动运行一次软提交,这将使您的文档对搜索可见,并每 10 分钟运行一次硬提交。
因此,无论您使用 SolrJ 添加什么:
solrClient.add(SolrInputDocument doc)
将在 30 秒后软提交,并在 10 分钟后硬提交,无需调用 solrClient.commit() 。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)