Search code examples
solrsolrj

Refresh index in Solr


In case of integration tests, before a tests starts I put documents in Solr, and wait (with a sleep...) for Solr to index.

With Elasticsearch, I know it is possible to refresh an index.

Is it possible to do the same with Solr ? And how to proceed ?


Solution

  • I suppose the reason you want to refresh the index is because you want near real time search. Essentially you want the search to reflect the added document instantaneously.

    In solr usually its controlled by softCommits or hardCommit with openSearcher=true.

    Read here more about this

    https://lucidworks.com/2013/08/23/understanding-transaction-logs-softcommit-and-commit-in-sorlcloud/

    The gist is this

    Hard commits are about durability, soft commits are about visibility

    Now if i understand you are doing this all for testing purpose, so you can not probably change the softcommit time for your collection(As this will have other implications).

    I think however you can force solr to commit the changes while indexing as follows:

    http://localhost:8983/solr/my_collection/update?softCommit=true 
    

    So adding softCommit=true will cause an explicit commit to happen. you can use the above after you add bunch of docs so that make all of them appear in the index together or alternatively you can add softCommit=true in each request for indexing doc.

    However every time you do a soft commit it invalidates all top level caches.(Read more about all this in the above link.)

    Note: Please be aware however the usual recommendation is to not call commits externally.