diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index f5f12d4fd24..8ce5901b353 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -334,14 +334,23 @@ public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin, Reloa @Override public void afterBulk(long executionId, BulkRequest request, BulkResponse response) { if (response.hasFailures()) { - Map triggeredWatches = Arrays.stream(response.getItems()) + Map triggeredFailures = Arrays.stream(response.getItems()) .filter(BulkItemResponse::isFailed) .filter(r -> r.getIndex().startsWith(TriggeredWatchStoreField.INDEX_NAME)) .collect(Collectors.toMap(BulkItemResponse::getId, BulkItemResponse::getFailureMessage)); - if (triggeredWatches.isEmpty() == false) { - String failure = triggeredWatches.values().stream().collect(Collectors.joining(", ")); + Map historyFailures = Arrays.stream(response.getItems()) + .filter(BulkItemResponse::isFailed) + .filter(r -> r.getIndex().startsWith(HistoryStoreField.INDEX_PREFIX)) + .collect(Collectors.toMap(BulkItemResponse::getId, BulkItemResponse::getFailureMessage)); + if (triggeredFailures.isEmpty() == false) { + String failure = triggeredFailures.values().stream().collect(Collectors.joining(", ")); logger.error("triggered watches could not be deleted {}, failure [{}]", - triggeredWatches.keySet(), Strings.substring(failure, 0, 2000)); + triggeredFailures.keySet(), Strings.substring(failure, 0, 2000)); + } + if (historyFailures.isEmpty() == false) { + String failure = historyFailures.values().stream().collect(Collectors.joining(", ")); + logger.error("watch history could not be written {}, failure [{}]", + historyFailures.keySet(), Strings.substring(failure, 0, 2000)); } Map overwrittenIds = Arrays.stream(response.getItems())