[ 
https://issues.apache.org/jira/browse/NIFI-5266?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16502093#comment-16502093
 ] 

ASF GitHub Bot commented on NIFI-5266:
--------------------------------------

Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2760#discussion_r193145047
  
    --- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchHttp.java
 ---
    @@ -288,42 +290,23 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
                 session.read(file, in -> {
                     json.append(IOUtils.toString(in, charset).replace("\r\n", 
" ").replace('\n', ' ').replace('\r', ' '));
                 });
    -            if (indexOp.equalsIgnoreCase("index")) {
    -                sb.append("{\"index\": { \"_index\": \"");
    -                sb.append(index);
    -                sb.append("\", \"_type\": \"");
    -                sb.append(docType);
    -                sb.append("\"");
    -                if (!StringUtils.isEmpty(id)) {
    -                    sb.append(", \"_id\": \"");
    -                    sb.append(id);
    -                    sb.append("\"");
    -                }
    -                sb.append("}}\n");
    -                sb.append(json);
    -                sb.append("\n");
    -            } else if (indexOp.equalsIgnoreCase("upsert") || 
indexOp.equalsIgnoreCase("update")) {
    -                sb.append("{\"update\": { \"_index\": \"");
    -                sb.append(index);
    -                sb.append("\", \"_type\": \"");
    -                sb.append(docType);
    -                sb.append("\", \"_id\": \"");
    -                sb.append(id);
    -                sb.append("\" }\n");
    -                sb.append("{\"doc\": ");
    -                sb.append(json);
    -                sb.append(", \"doc_as_upsert\": ");
    -                sb.append(indexOp.equalsIgnoreCase("upsert"));
    -                sb.append(" }\n");
    -            } else if (indexOp.equalsIgnoreCase("delete")) {
    -                sb.append("{\"delete\": { \"_index\": \"");
    -                sb.append(index);
    -                sb.append("\", \"_type\": \"");
    -                sb.append(docType);
    -                sb.append("\", \"_id\": \"");
    -                sb.append(id);
    -                sb.append("\" }\n");
    +
    +            String jsonString = json.toString();
    +
    +            // Ensure the JSON body is well-formed
    +            try {
    --- End diff --
    
    will change to static. A generally available one would be good, just need 
to find the right place (like a utility JAR) and make sure it doesn't interfere 
with other bundles using it (like if they need their own Jackson or don't want 
all the Jackson dependencies when they resolve the utility JAR)


> PutElasticsearchHttp processors should sanitize parameters
> ----------------------------------------------------------
>
>                 Key: NIFI-5266
>                 URL: https://issues.apache.org/jira/browse/NIFI-5266
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Extensions
>            Reporter: Matt Burgess
>            Assignee: Matt Burgess
>            Priority: Major
>
> Currently PutElasticsearchHttp and PutElasticsearchHttpRecord put the 
> property values for index, type, and id into the Bulk API command as they are 
> specified in the processor properties. This can cause errors when special 
> characters such as a double-quote (") is encountered. Although a double-quote 
> (for example) is not supported in an index name, it is valid in a type name 
> and should be allowed.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to