How to identify documents failed in a Solr batch request?

382 Views Asked by At

I am using the following code to send documents to Solr:

    final UpdateRequest request = new UpdateRequest();
    request.setAction(UpdateRequest.ACTION.COMMIT, false, false);
    request.add(docsList);
    UpdateResponse response = request.process(solrClient);

The response returned from the last line does not seem to be very helpful in determining how I can identify documents failed in a batch request.

Does anyone know how this can be done?

1

There are 1 best solutions below

0
On

You're looking for the getStatus() method as:

UpdateResponse updateResponse = request.process(solrClient);
int responseStatus = updateResponse.getStatus()

That will return some of the error as per SolrEception like:

  • 503 SERVICE_UNAVAILABLE
    • 500 SERVER_ERROR
    • 404 NOT_FOUND
    • 403 FORBIDDEN
    • 401 UNAUTHORIZED
    • 400 BAD_REQUEST

That won't tell you what document failed, however I suggest to identify a subset of error codes that require to get the doc number that failed and in those cases you could re-index document by document and stop when you get an error. In such case it would be better to use small batches.