title: In Elasticsearch does the Update By Query API increment an external version of updated documents?
body: <p>We are indexing <code>cars</code> documents in Elasticsearch with an <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#index-version-types" rel="nofollow noreferrer"><code>external</code></a> version.</p>
  <p>We are then sometimes updating the <code>cars</code> documents using the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html" rel="nofollow noreferrer">Update By Query API</a> and <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-painless.html" rel="nofollow noreferrer">Painless scripting language</a>. The update request looks like this:</p>
  <pre><code>POST http://search/cars/_update/445398312253724778?routing=91e2c33a-52f5-43f4-b8c5-6fb5673ff6e0&amp;refresh=true&amp;timeout=1m
  
  {
    &quot;script&quot;: {
      &quot;source&quot;: &quot;if (ctx._source.status != 'NEW') { ctx.op = 'noop' } ctx._source.transition = params.status&quot;,
      &quot;lang&quot;: &quot;painless&quot;,
      &quot;params&quot;: {
        &quot;status&quot;: &quot;OBSOLETE&quot;
      }
    },
    &quot;scripted_upsert&quot;: true
  }
  </code></pre>
  <p>It seems that the version of the documents is not increased when using the Update By Query API. I also couldn't find anything regarding the updating of versions in the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html" rel="nofollow noreferrer">Update By Query API documentation</a>.</p>
  <p>However, according to <a href="https://www.elastic.co/blog/elasticsearch-versioning-support" rel="nofollow noreferrer">Elasticsearch' blog post detailing Elasticsearch Versioning Support</a>,</p>
  <blockquote>
  <p>With every write-operation to this document, whether it is an
  index,update or delete, Elasticsearch will increment the version by 1.</p>
  </blockquote>
  <p>I am confused now. Does the Update By Query API increment the <code>external</code> version of updated documents?</p>