问题
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?
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/5623307/solrj-disable-autocommit