Skip to content

Commit

Permalink
Merge pull request #3297 from lorthirk/fix-improveEsUpsertFailedError…
Browse files Browse the repository at this point in the history
…Message

Improve Upsert Failed Error Message in Elasticsearch REST Client
  • Loading branch information
Claudio Mezzasalma authored Apr 27, 2021
2 parents 82c158b + 7a3971a commit a2e1700
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.ParseException;
import org.apache.http.util.EntityUtils;
import org.eclipse.kapua.commons.metric.MetricServiceFactory;
Expand Down Expand Up @@ -240,6 +241,10 @@ public BulkUpdateResponse upsert(BulkUpdateRequest bulkUpdateRequest) throws Cli
if (failureNode != null) {
failureMessage = failureNode.asText();
}
String reason = jsonNode.at("/error/reason").asText();
if (StringUtils.isNotBlank(reason)) {
failureMessage = reason;
}
bulkResponse.add(new UpdateResponse(metricId, new TypeDescriptor(indexName, typeName), failureMessage));
LOG.info("Upsert failed [{}, {}, {}]", indexName, typeName, failureMessage);
continue;
Expand Down

0 comments on commit a2e1700

Please sign in to comment.