Data that is synchronized to the Search service is visible only after the data is committed. You can specify the time when the data is committed by using one of the following methods: soft commit or hard commit.
Configure the solrconfig.xml file
You must specify the configuration set named config set
when you create an index. You can use the solrconfig.xml
file in the configuration set to control the visibility of the data in the index.
soft commit
<autoSoftCommit> <maxTime>${solr.autoSoftCommit.maxTime:15000}</maxTime> </autoSoftCommit>
By default, the data can be queried 15 seconds after a soft commit is executed.
hard commit
<autoCommit> <maxTime>${solr.autoCommit.maxTime:30000}</maxTime> <openSearcher>false</openSearcher> </autoCommit>
By default, the data is flushed to the disk 30 seconds after a hard commit is executed.
Compared with a hard commit, a soft commit requires less time to complete.
We recommend that you specify a sufficient amount of time. Otherwise, the Search service frequently flushes data to the disk, which affects the write performance. Use the default value.
How it takes effect
Download the required configuration set.
Modify the time of the
soft commit
and thehard commit
.Update the configuration set.
./solr zk upconfig -d conf/ -n myconf
Reload Collection
Client parameters
If you do not want to modify the solrconfig.xml file on the server, you can explicitly call the commit method to make the data visible when you separately write the data to the Search index.
commitWithinMs
// The second parameter commitWithinMs can be used to control when the current data can be queried. public UpdateResponse add(SolrInputDocument doc, int commitWithinMs) throws SolrServerException, IOException;
For example, you can specify that data can be queried 10 seconds after the synchronization.
cloudSolrClient.add(doc, 1000);
commit API
// After the synchronization, you can explicitly call the commit operation to specify the time when the data is committed by the server to ensure that the data can be queried. public UpdateResponse commit(boolean waitFlush, boolean waitSearcher, boolean softCommit) throws SolrServerException, IOException;
For example, you can specify that the server immediately executes a soft commit.
cloudSolrClient.commit(false, false, true);