0

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

4

2 回答 2

4

您不能禁用和启用自动提交,因为它是在 solrconfig.xml 中配置的。但是,您可以在 solrconfig.xml 中将其禁用,并将commitWithin 用于那些需要 autocommit 的添加命令

于 2011-04-11T16:15:55.567 回答
2

回答是因为这是“solr disable autocommit”的第一个结果。
这现在可以通过新的配置 API实现,该 API允许覆盖 solrconfig.xml 中设置的一些属性,而无需重新加载核心。
Solrj 还没有实现那个新的 API。

您不应该禁用自动提交,请参阅这篇文章

如果您想一次对许多文档进行批量索引,请设置updateHandler.autoCommit.openSearcher=false并禁用 autoSoftCommits:

/**
 * 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);
}

您可以在以下位置查看覆盖的属性http://localhost:8983/solr/<core>/config/overlay

于 2016-08-11T16:09:27.580 回答