title: Replacing (Bulk Update) Nested documents in ElasticSearch
body: <p>I have an ElasticSearch index with vacation rentals (100K+), each including a property with nested documents for availability dates (1000+ per 'parent' document). Periodically (several times daily), I need to replace the entire set of nested documents for each property (to have fresh data for availability per vacation rental property) - however ElasticSearch default behavior is to merge nested documents.</p>
  
  <p>Here is a snippet of the mapping (availability dates in the "bookingInfo"):</p>
  
  <pre><code>{
     "vacation-rental-properties": {
        "mappings": {
           "property": {
              "dynamic": "false",
              "properties": {
                 "bookingInfo": {
                    "type": "nested",
                    "properties": {
                       "avail": {
                          "type": "integer"
                       },
                       "datum": {
                          "type": "date",
                          "format": "dateOptionalTime"
                       },
                       "in": {
                          "type": "boolean"
                       },
                       "min": {
                          "type": "integer"
                       },
                       "out": {
                          "type": "boolean"
                       },
                       "u": {
                          "type": "integer"
                       }
                    }
                 },
                 // this part left out
              }
          }
      }
  }
  </code></pre>
  
  <p>Unfortunately, our current underlying business logic does not allow us to replace or update parts of the "bookingInfo" nested documents, we need to replace the entire array of nested documents. With the default behavior, updating the 'parent' doc, merely adds new nested docs to the "bookingInfo" (unless they exist, then they're updated) - leaving the index with a lot of old dates that should no longer be there (if they're in the past, they're not bookable anyway).</p>
  
  <p>How do I go about making the update call to ES?</p>
  
  <p>Currently using a bulk call such as (two lines for each doc):</p>
  
  <pre><code>{ "update" : {"_id" : "abcd1234", "_type" : "property", "_index" : "vacation-rental-properties"} }
  { "doc" : {"bookingInfo" : ["all of the documents here"]} }
  </code></pre>
  
  <p>I have found <a href="https://stackoverflow.com/questions/18360225/elastic-search-is-it-possible-to-update-nested-objects-without-updating-the-ent">this question</a> that seems related, and wonder if the following will work (first enabling scripts via <code>script.inline: on</code> in the config file for version 1.6+):</p>
  
  <pre><code>curl -XPOST localhost:9200/the-index-and-property-here/_update -d '{
      "script" : "ctx._source.bookingInfo = updated_bookingInfo",
      "params" : {
          "updated_bookingInfo" : {"field": "bookingInfo"}
      }
  }'
  </code></pre>
  
  <ul>
  <li>How do I translate that to a bulk call for the above?</li>
  </ul>