Mrinalini Hanagodu
Mrinalini Hanagodu

Reputation: 21

Modifying solrconfig.xml from SolrJ?

I want to modify the solrconfig.xml file from my java code. If there is any source which gives examples of implementation of abstract SolrRequest in SolrJ for modifying solrconfig.xml, could you please point me out to them.

Thanks

Upvotes: 1

Views: 775

Answers (2)

Bikas Katwal
Bikas Katwal

Reputation: 2035

As @MatsLindh said, you can use Config API to update solr configs. You do not need to reload the collection either.

You can find command properties for config API here

Below is code for the newer version of Solr (>7.0), that updates property updateHandler.autoSoftCommit.maxTime:

//setting softCommit maxTime to 15000
final String command = "{\"set-property\":{\"updateHandler.autoSoftCommit.maxTime\":15000}}";

//path and method of request
final GenericSolrRequest rq = new GenericSolrRequest(SolrRequest.METHOD.POST, "/config", null);

// request string and request type
final ContentWriter content = new StringPayloadContentWriter(command, "application/json");

rq.setContentWriter(content);

//create your solrClient using zookeeper connection string
rq.process(solrClient, "<your collection name>");

You can find equivalent curl command here

Upvotes: 0

MatsLindh
MatsLindh

Reputation: 52792

You can't modify solrconfig.xml directly from the API, but you can use the Config API to modify configuration without having to edit solrconfig.xml.

The Config API creates an "overlay" that is used on top of the settings defined in solrconfig, and allows you to manipulate most aspects that is contained in the config file.

You can see how to manually build JSON and set it with SolrJ. I'm not sure if there's been anything added to SolrJ to abstract this away, but open tickets on the issue tracker indicate that it hasn't happened yet. It would also depend on which version of SolrJ you're using.

Upvotes: 2

Related Questions