title: How do I dynamically update the fields of a document?
body: <p>I'm building a basic crud app for storing movie/tv titles. I am using version 2.4.4 of elasticsearch because my project manager chose this version.  I am using the express framework along with the native elasticsearch nodejs driver.</p>
  
  <p>Currently this is what my mappings look like for the "titles" index for a "title" type. </p>
  
  <pre><code>client.indices.create({
        index: "titles",
        body: {
          "mappings": {
            "title": {
              "properties": {
                "seriesName":           { "type": "string", "index": "not_analyzed" },
                "seriesEpisodeNumber":  { "type": "long", "index": "not_analyzed" },
                "seriesEpisodeTitle":   { "type": "string", "index": "not_analyzed" },
                "isDeleted":            { "type": "boolean", "index": "not_analyzed" }
              }
            }
          }
        }
      }).
  </code></pre>
  
  <p>I want to have an endpoint on my server that updates the document by its id. This is what I have so far for this endpoint " POST /api/titles/:titleID/updateTitleByID"</p>
  
  <pre><code>titlesController.updateTitleByID = function(req,res){
    const titleID = req.params.titleID;
    es.updateByQuery({
      index: "titles",
      type: "title",
      body: {
        query: {
          bool: {
            must: [{
              term: {
                _id: titleID
              }},{
                term: {
                  isDeleted: false 
                }}]
          }
        },
        script: {
          inline: "ctx._source.seriesName = seriesName;ctx._source.seriesEpisodeNumber = seriesEpisodeNumber; ctx._source.seriesEpisodeTitle = seriesEpisodeTitle;",
          params: { ...req.body }
        }
      }}).then(results =&gt; {
        logger.info(results);
        res.status(200).json({
          message: "OK"
        });
      }).catch(err =&gt; {
        logger.error(err);
        res.status(500).json({
          error: "Internal server error"
        });
      });
  };
  </code></pre>
  
  <p>What I want to achieve is to update the document with what ever I get from my req.body. For example if I get a seriesName I from the request body. That is only what I want to update and leave the rest untouched. How do I achieve this?</p>
  
  <p>Edit: Here is the full stack trace</p>
  
  <pre><code>Error: [remote_transport_exception] [Agon][127.0.0.1:9300][indices:data/write/update[s]]
      at respond (/home/natealcedo/Projects/digitalfolks.hooq/node_modules/elasticsearch/src/lib/transport.js:289:15)
      at checkRespForFailure (/home/natealcedo/Projects/digitalfolks.hooq/node_modules/elasticsearch/src/lib/transport.js:248:7)
      at HttpConnector.&lt;anonymous&gt; (/home/natealcedo/Projects/digitalfolks.hooq/node_modules/elasticsearch/src/lib/connectors/http.js:164:7)
      at IncomingMessage.wrapper (/home/natealcedo/Projects/digitalfolks.hooq/node_modules/lodash/lodash.js:4968:19)
      at emitNone (events.js:91:20)
      at IncomingMessage.emit (events.js:186:7)
      at endReadableNT (_stream_readable.js:974:12)
      at _combinedTickCallback (internal/process/next_tick.js:74:11)
      at process._tickDomainCallback (internal/process/next_tick.js:122:9)
  </code></pre>