Hello everybody,
I use BulkProcessor and want to get the number of failure messages in BulkResponse. With the current APIs, I see 2 ways.
Way 1: iterate over BulkResponse and count
@Override
public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
int failActions = 0;
if (response.hasFailures()) {
System.out.println("bulk process has failure: " + response.buildFailureMessage());
for (BulkItemResponse item: response) {
if (item.isFailed()) failActions++;
}
}
Way 2: count the line number in failureMessage string (returned from response.buildFailureMessage()
). It seems a bit tricky because it assumes there is no new line inside each BulkItemResponse's failure.
I wonder if it would be better to have getFailureNumber()
in BulkResponse.
Regards,
trango