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

    https://github.com/apache/nifi/pull/255#discussion_r67496113
  
    --- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearch.java
 ---
    @@ -178,8 +190,20 @@ 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")) 
{
    --- End diff --
    
    The difference is about how ES will handle it.
    
    See 
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#upserts.
 "The update API also support passing a partial document, which will be merged 
into the existing document .... instead of sending a partial doc plus an upsert 
doc, setting doc_as_upsert to true will use the contents of doc as the upsert 
value".
    
    You will see the difference when you upsert two or more documents like this:
    
    first time upserting: doc1 `{ "prop1": [...] }`
    
    second time upserting: doc1 `{ "prop2": [...]}`
    
    And the final doc1 should be: { "prop1": [...],  "prop2": [...]}



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to