SolrJ:禁用自动提交

发布于 2024-11-01 01:41:39 字数 157 浏览 0 评论 0原文

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

We have an instance of Solr, where we've found that turning on autoCommit in the solrconfig.xml actually may serve our needs well. However there are some instances and some batch operations where we want to temporarily disable autocommit. I have not been able to find anything, but I'm wondering if anyone knew if via SolrJ you could disable autocommit for a certain process, and then re-enable it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阳光下慵懒的猫 2024-11-08 01:41:39

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

You can't disable and enable autocommit as it's configured in solrconfig.xml. However, you can leave it disabled in solrconfig.xml and use commitWithin for those add commands that need autocommit.

梦行七里 2024-11-08 01:41:39

回答是因为这是“solr 禁用自动提交”的第一个结果。
现在可以使用允许覆盖某些属性的新配置 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/<核心>/config/overlay

answering because this is the first result for "solr disable autocommit".
This is now possible with the new config API that allows to override some properties set in solrconfig.xml without reloading the core.
Solrj does not implement that new API yet.

You should not disable autocommits, see this article.

If you want to do a bulk indexing of many documents at once, set updateHandler.autoCommit.openSearcher=false and disable 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);
}

You can see the overriden properties at http://localhost:8983/solr/<core>/config/overlay

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文