Search code examples
javasolrsolrj

solrj solrclient.add collection order


I am creating a list of SolrInputDocuments with atomic updates to be indexed in Solr 6 (no SolrCloud, no Shards, just a single Solr core).

Is there an order difference in how the documents will be indexed and committed to Solr if I give:

a. this collection directly to the add method of the client or

b. if I externally loop through them and add them individually with the client?

Directly add the collection:

final SolrClient solr = createMySolrClient() // custom method
List<SolrInputDocument> solrDocsToIndex = createMySolrDocs() // custom method
solr.add(solrDocsToIndex);
solr.commit();

Add via external loop:

final SolrClient solr = createMySolrClient() // custom method
List<SolrInputDocument> solrDocsToIndex = createMySolrDocs() // custom method
for (SolrInputDocument solrDocToIndex : solrDocsToIndex) {
    solr.add(solrDocToIndex);
}
solr.commit();

In my usecase, the order in which these documents are stored in the list needs to be the order in which Solr will process the atomic updates.

Can directly adding the collection to the add method as shown above already accomplish this?


Solution

  • If you check the code here, you can see that the mentioned code calls UpdateRequest.add(Collection docs) whose cycles on the collection provided in the same way you mentioned in your second use case. So the order will be maintained in both the proposed use cases.