ChrisSamo632 commented on code in PR #6903:
URL: https://github.com/apache/nifi/pull/6903#discussion_r1114446805


##########
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/AbstractPutElasticsearch.java:
##########
@@ -158,15 +200,38 @@ void transferFlowFilesOnException(final Exception ex, 
final Relationship rel, fi
         }
     }
 
-    void logElasticsearchDocumentErrors(final IndexOperationResponse response) 
throws JsonProcessingException {
-        if (logErrors || getLogger().isDebugEnabled()) {
-            final List<Map<String, Object>> errors = response.getItems();
-            final String output = String.format("An error was encountered 
while processing bulk operations. Server response below:%n%n%s", 
errorMapper.writeValueAsString(errors));
+    void handleElasticsearchDocumentErrors(final IndexOperationResponse 
response, final List<Integer> errorIndices, final ProcessSession session, final 
FlowFile parent) throws IOException {
+        if (!errorIndices.isEmpty() && (outputErrorResponses || logErrors || 
getLogger().isDebugEnabled())) {
+            final List<Map<String, Object>> errorResponses = 
errorIndices.stream().map(index -> 
response.getItems().get(index)).collect(Collectors.toList());
 
-            if (logErrors) {
-                getLogger().error(output);
-            } else {
-                getLogger().debug(output);
+            if (logErrors || getLogger().isDebugEnabled()) {
+                final String output = String.format(
+                        "An error was encountered while processing bulk 
operations. Server response below:%n%n%s",
+                        errorMapper.writeValueAsString(errorResponses)
+                );
+
+                if (logErrors) {
+                    getLogger().error(output);
+                } else {
+                    getLogger().debug(output);
+                }
+            }
+
+            if (outputErrorResponses) {
+                FlowFile errorResponsesFF = null;
+                try {
+                    errorResponsesFF = session.create(parent);
+                    try (final OutputStream errorsOutputStream = 
session.write(errorResponsesFF)) {
+                        errorMapper.writeValue(errorsOutputStream, 
errorResponses);
+
+                        errorResponsesFF = 
session.putAttribute(errorResponsesFF, "elasticsearch.put.error.count", 
String.valueOf(errorResponses.size()));

Review Comment:
   Seemed to work OK when I tried it, but should be able to move this outside 
of the try-with-resources if you've seen it cause problems in the past



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to