How to handle fine grained errors in new Java API 8.0.1 for Bulk?

With much sweat I could build a Bulk Request, on the new Java API 8.1.0, like this

// build request
ArrayList<BulkOperation> bulkOperations = new ArrayList<BulkOperation>();
BulkOperation bulkOperation = BulkOperation.of(b -> b.index(i -> i.index(indexes).id(qesdocument.idValue()).document(jsonData)) );
bulkOperations.add(bulkOperation);

// run request
bulkResponse = client.bulk(b -> b.index(indexes).operations(bulkOperations));

// handle errors
if (bulkResponse.errors()) {  .....

When issued on a bulk of hundreds of documents, not all of them made it to Elasticsearch.
There were errors , on some documents , somewhere ...

How can I handle fine grained errors to investigate what went wrong , just like what was provided in in the HLRC ?

You have to iterate over the response hits.
You can do that with a stream and a filter to only collect the hits which have an error.

Ok, did this, (old style programming)


          if (bulkResponse.errors()) {

              System.out.println("Erreur occured");

              for (BulkResponseItem bulkResponseItem : bulkResponse.items()) {
                  if (bulkResponseItem.error() != null) {
                      System.out.println("Erreur id", bulkResponseItem.id());
                      System.out.println("Erreur seqNo", bulkResponseItem.seqNo());
                      System.out.println("Erreur result", bulkResponseItem.result());
                      System.out.println("Erreur type", bulkResponseItem.error().type());
                      System.out.println("Erreur reason", bulkResponseItem.error().reason());
                      System.out.println("Erreur caused by", bulkResponseItem.error().causedBy().reason());
                      System.out.println("Erreur String", bulkResponseItem.error().toString());
                      System.out.println("Erreur stackTrace", bulkResponseItem.error().stackTrace());
                  }
              }

          }

@ivanqwam can you elaborate on that? What exactly are you referring to? This can be valuable information to improve the new client.

Thanks.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.