We are indexing cars
documents in Elasticsearch with an external
version.
We are then sometimes updating the cars
documents using the Update By Query API and Painless scripting language. The update request looks like this:
POST http://search/cars/_update/445398312253724778?routing=91e2c33a-52f5-43f4-b8c5-6fb5673ff6e0&refresh=true&timeout=1m
{
"script": {
"source": "if (ctx._source.status != 'NEW') { ctx.op = 'noop' } ctx._source.transition = params.status",
"lang": "painless",
"params": {
"status": "OBSOLETE"
}
},
"scripted_upsert": true
}
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 Update By Query API documentation.
However, according to Elasticsearch' blog post detailing Elasticsearch Versioning Support,
With every write-operation to this document, whether it is an index,update or delete, Elasticsearch will increment the version by 1.
I am confused now. Does the Update By Query API increment the external
version of updated documents?
CodePudding user response:
When you index a document with external versioning, you're only providing an external version number, that's it, ES will not do anything else than store the version you're giving it. The document itself is not flagged as being externally versioned.
When updating a single document, you can again provide an external version number.
But when updating by query, the only versioning that can be used is internal (i.e. version ), because the whole update process happens internally to ES, as you're not able to provide any external version number