title: Update index with script in ElasticSearch Bulk JavaScript API
body: <p>I'm using ElasticSearch <strong>Update</strong> action with <a href="https://www.elastic.co/guide/en/elasticsearch/reference/6.5/docs-update.html#upserts" rel="nofollow noreferrer">Upserts</a> to create or update an existing document in the current Index, when doing in the <a href="https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-6-5.html#api-bulk-6-5" rel="nofollow noreferrer">bulk</a> api like this </p>
  
  <pre><code>{
                      index: myIndex,
                      type: '_doc',
                      body: [
                      { index:  {_id: docItemID1 } },
                      docItem1,
                      { index:  {_id: docItemID2 } },
                      docItem2
  ]
                  }
  </code></pre>
  
  <p>This works ok. Now I would like to update / append a new value to a <code>tag</code> field in the document item using the <code>scripted_upsert</code> flag and the <code>script</code> update action so something like:</p>
  
  <pre><code>{
     "scripted_upsert":true,
      "script" : {
          "source": "if ( !ctx._source.tags.contains(params.tag) ) ctx._source.tag.concat( params.tag)",
          "lang": "painless",
          "params" : {
              "tag" : "blue"
          }
      },
      "upsert" : {
          "tag" : ["red","green"]
      }
  }
  </code></pre>
  
  <p>Now, I want to use the <code>scripted_upsert</code> to take the best of the two worlds, so I imagine something like this - if it is correct (that is my question)</p>
  
  <pre><code>    {
          "script" : {
              "source": "if ( !ctx._source.tags.contains(params.tag) ) ctx._source.tag.concat( params.tag)",
              "lang": "painless",
              "params" : {
                  "tag" : myNewTag
              }
          },
          "upsert" : docItem
      }
  </code></pre>
  
  <p>where <code>docItem</code> will contain a <code>tag</code> item to be updated. This tag items is a comma separated list of tags like <code>red,green</code>. </p>
  
  <p>Is this approach correct? If so which is the right body for the <code>bulk</code> api i.e. when using the <code>body</code> as <code>[]</code> of actions having an update <code>script</code> with plus <code>scripted_upsert</code> flag for one or more items?</p>