It would seem that partial updates to documents using the update API will fail if the document was change before the update was applied:
To avoid losing data, the update API retrieves the current _version of the document in the retrieve step, and passes that to the index request during the reindex step. If another process has changed the document between retrieve and reindex, then the _version number won’t match and the update request will fail.
It then goes on to say that you can supply retry_on_conflict which would retry the write if a conflict does occur:
For many uses of partial update, it doesn’t matter that a document has been changed...
This can be done automatically by setting the retry_on_conflict parameter to the number of times that update should retry before failing; it defaults to 0.
So if I use the update API with retry_on_conflict of say 3, without supplying the _version field, that ES will internally fail once (if a conflict does occur), and then retry and overwrites the value that it was conflicting with?
It would seem so, because
...the update API adopts a last-write-wins approach by default
Source: https://www.elastic.co/guide/en/elasticsearch/guide/current/partial-updates.html#_updates_and_conflicts
Note: I'm using ES 1.5
Yes, that's about it. A clarification regarding retry and overwrites the value that it was conflicting with statement: the conflict was with the version of the document (not an arbitrary field within your document), let's make this clear, and it was an internal conflict between ES GETing the document and actually writing the new (updated) document (these two actions being part of the _update operation).
And it is not overriding a value it is conflicting with, it is another update operation that will succeed as soon as the versions checks are ok and, yes, will update the document in the index.
If you need to make sure your updates go in a certain order you need to use version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With