2011-04-11 86 views
0

我们有一个Solr实例,我们发现在solrconfig.xml中打开autoCommit实际上可以满足我们的需求。但是有一些实例和一些批处理操作,我们希望暂时禁用自动提交。我一直无法找到任何东西,但我想知道是否有人通过SolrJ知道你可以禁用某个进程的自动提交,然后重新启用它?SolrJ:禁用自动提交

+0

/** * Disables the autoSoftCommit feature. * Use {@link #reEnableAutoCommit()} to reenable. * @throws IOException network error. * @throws SolrServerException solr error. */ public void disableAutoSoftCommit() throws SolrServerException, IOException { // Solrj does not support the config API yet. String command = "{\"set-property\": {" + "\"updateHandler.autoSoftCommit.maxDocs\": -1," + "\"updateHandler.autoSoftCommit.maxTime\": -1" + "}}"; GenericSolrRequest rq = new GenericSolrRequest(SolrRequest.METHOD.POST, "/config", null); ContentStream content = new ContentStreamBase.StringStream(command); rq.setContentStreams(Collections.singleton(content)); rq.process(solrClient); } /** * Undo {@link #disableAutoSoftCommit()}. * @throws IOException network error. * @throws SolrServerException solr error. */ public void reenableAutoSoftCommit() throws SolrServerException, IOException { // Solrj does not support the config API yet. String command = "{\"unset-property\": [" + "\"updateHandler.autoSoftCommit.maxDocs\"," + "\"updateHandler.autoSoftCommit.maxTime\"" + "]}"; GenericSolrRequest rq = new GenericSolrRequest(SolrRequest.METHOD.POST, "/config", null); ContentStream content = new ContentStreamBase.StringStream(command); rq.setContentStreams(Collections.singleton(content)); rq.process(solrClient); } 

你可以看到被覆盖的属性,你可以请解释一下什么是需要:

如果你想同时做很多文档的批量索引,设置updateHandler.autoCommit.openSearcher=false和禁用autoSoftCommits在solrconfig.xml中设置自动提交的问题 – Romi 2011-05-27 10:58:07

回答

3

您无法禁用并启用自动提交,因为它在solrconfig.xml中配置。但是,您可以在solrconfig.xml中将其禁用,并使用commitWithin for those add commands that need autocommit

+0

嗨,是否仍然可以在solr 3.6中使用solrj? solr.commitWithin(5000);似乎并不存在。 – DavidVdd 2012-09-07 09:37:48

1

回答是因为这是“solr disable autocommit”的第一个结果。
现在可以使用new config API,它允许覆盖solrconfig.xml中设置的某些属性而不重新加载内核。
Solrj尚未实现该新API。

您不应该禁用自动提交,请参阅this article。在http://localhost:8983/solr/<core>/config/overlay