solrsolrjsolr5autocommit

Achieve soft-commit programmatically


AutoSoftCommit and autoCommit are configured at solrConfig.xml.

Can I configure these settings at my application level using Java?

What I want to know is, Can I configure autoSoftCommit and autoCommit using SolrJ library?

Reason I am asking this question is, application is a springBoot app with API and solr both bundled in the same build. And same build is used as master(indexer) and slaves(replicated through index replication using http call -

http://slave_machine/coreName/replication?masterUrl=http://master_machine/coreName&command=fetchindex)

If I modify solrconfig.xml, it will be changed for master as well as slave.


Solution

  • You can replicate different files to your clients - it doesn't have to be the same as the configuration file for the master node.

    <requestHandler name="/replication" class="solr.ReplicationHandler" >
        <lst name="master">
          [....]
          <str name="confFiles">solrconfig-slave.xml:solrconfig.xml,schema.xml,stopwords.txt</str>
        </lst>
    </requestHandler>
    

    This will replicate the file solrconfig-slave.xml on the master as solrconfig.xml on the slave, allowing you to have complete control over the setting for both the master and the slaves.

    If you're running in cloud mode (which it seems you aren't, since you're talking about explicit replication), the autoCommit values can be set for the whole collection on the cluster using the Config API and the updateHandler.autoCommit.* values (this is also valid for a single server, but you have to call the config API for each server in that case, since settings aren't distributed across servers automagically).

    The other alternative is to use commitWithin instead, which can be sent per request - allowing you to tell Solr that it can wait up to N milliseconds before committing the content to the index. This is usually the preferred way, since it allows you to index from multiple threads and servers without doing explicit commits - so that your commits doesn't conflict with each other.