SolrJ: Disable Autocommit

╄→гoц情女王★ 提交于 2019-12-02 07:46:43

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!