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

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

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

    https://github.com/apache/nifi/pull/255#discussion_r66067616
  
    --- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearch.java
 ---
    @@ -178,8 +190,18 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
                             public void process(final InputStream in) throws 
IOException {
                                 String json = IOUtils.toString(in, charset)
                                         .replace("\r\n", " ").replace('\n', ' 
').replace('\r', ' ');
    -                            bulk.add(esClient.get().prepareIndex(index, 
docType, id)
    -                                    .setSource(json.getBytes(charset)));
    +
    +                            if (indexOp.equalsIgnoreCase("index")) {
    +                                
bulk.add(esClient.get().prepareIndex(index, docType, id)
    +                                        
.setSource(json.getBytes(charset)));
    +                            } else if (indexOp.equalsIgnoreCase("upsert")) 
{
    +                                
bulk.add(esClient.get().prepareUpdate(index, docType, id)
    +                                        .setDoc(json.getBytes(charset))
    +                                        .setDocAsUpsert(true));
    +                            } else if (indexOp.equalsIgnoreCase("update")) 
{
    +                                
bulk.add(esClient.get().prepareUpdate(index, docType, id)
    +                                        .setDoc(json.getBytes(charset)));
    +                            }
    --- End diff --
    
    If the index operation is not one of these three values, it looks like the 
file is quietly ignored and still transferred to success. Can you add an else 
clause that throws an IOException, and unit test(s) to test these code paths?


> Add option to bulk using Index or Update to PutElasticsearch
> ------------------------------------------------------------
>
>                 Key: NIFI-1594
>                 URL: https://issues.apache.org/jira/browse/NIFI-1594
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Extensions
>            Reporter: João Henrique Ferreira de Freitas
>            Priority: Minor
>             Fix For: 1.0.0, 0.7.0
>
>
> I have a use case where two flowfiles needs to be write using 
> PutElasticsearch. Both will write to the same document but in different 
> properties. 
> The proposal is to let the user choice if an Update operation or Index is 
> needed.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to