ChrisSamo632 commented on a change in pull request #4693:
URL: https://github.com/apache/nifi/pull/4693#discussion_r724795973



##########
File path: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecord.java
##########
@@ -426,22 +429,21 @@ public void onTrigger(ProcessContext context, 
ProcessSession session) {
         session.transfer(input, REL_SUCCESS);
     }
 
-    private void removeBadRecordFlowFiles(List<FlowFile> bad, ProcessSession 
session) {
-        for (FlowFile badFlowFile : bad) {
+    private void removeBadRecordFlowFiles(final List<FlowFile> bad, final 
ProcessSession session) {
+        for (final FlowFile badFlowFile : bad) {
             session.remove(badFlowFile);
         }
 
         bad.clear();
     }
 
-    private FlowFile indexDocuments(BulkOperation bundle, ProcessContext 
context, ProcessSession session, FlowFile input) throws Exception {
-        IndexOperationResponse response = 
clientService.bulk(bundle.getOperationList(), getUrlQueryParameters(context, 
input));
+    private FlowFile indexDocuments(final BulkOperation bundle, final 
ProcessContext context, final ProcessSession session, final FlowFile input) 
throws Exception {
+        final IndexOperationResponse response = 
clientService.bulk(bundle.getOperationList(), getUrlQueryParameters(context, 
input));
         if (response.hasErrors()) {
             if(logErrors || getLogger().isDebugEnabled()) {
-                List<Map<String, Object>> errors = response.getItems();
-                ObjectMapper mapper = new ObjectMapper();
-                mapper.enable(SerializationFeature.INDENT_OUTPUT);
-                String output = String.format("An error was encountered while 
processing bulk operations. Server response below:%n%n%s", 
mapper.writeValueAsString(errors));
+                final List<Map<String, Object>> errors = response.getItems();
+                objectMapper.enable(SerializationFeature.INDENT_OUTPUT);

Review comment:
       Moved it in to `onScheduled` instead - the ObjectMapper only needs to be 
created if errors are likely to be logged, so this will save unnecessary 
instantiations and setup
   
   Noticed that a similar change could be made in the 
`AbstractElasticsearchHttpProcessor` (part of `nifi-elasticsearch-processors`) 
as a new `ObjectMapper` was being created for parsing every response in each of 
the processors that inherrit that class




-- 
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