Skip to content

Commit

Permalink
Improve Upsert Failed Error Message in Elasticsearch REST Client
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Mezzasalma <claudio.mezzasalma@eurotech.com>
  • Loading branch information
Claudio Mezzasalma committed Apr 23, 2021
1 parent f9a15d3 commit 7a3971a
Showing 1 changed file with 5 additions and 0 deletions.
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 7a3971a

Please sign in to comment.