SolrJ: Disable Autocommit

前端 未结 2 1706
囚心锁ツ
囚心锁ツ 2021-01-29 02:13

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

相关标签:
2条回答
  • 2021-01-29 02:28

    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.

    0 讨论(0)
  • 2021-01-29 02:51

    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

    0 讨论(0)
提交回复
热议问题