Concurrency control of Update

I'm confused about the concurrency control of update. It seems that update does check for conflicts:

In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception.

Also there are two parameters if_seq_no and if_primary_term related to concurrency control. According to the documentation, maybe, the default check of update uses versioning while if_seq_no and if_primary_term can be provided manually. However, according to here maybe checking according to versioning is not reliable and seq_no and primary_term must be used instead. Can I rely on update's own checking for conflicts?

Yes. Internally the update is using the reliable if_seq_no and if_primary_term mechanism to detect conflicting updates.

So when should we manually use if_seq_no and if_primary_term?

I'm not sure I'm understanding the question. You should use the explicit concurrency control mechanism (i.e. if_seq_no and if_primary_term) if you want explicit control over the behaviour of concurrent operations.

It seems that Update checks for conflicts by default, without mentioning if_seq_no and if_primary_term and you said:

Yes. Internally the update is using the reliable if_seq_no and if_primary_term mechanism to detect conflicting updates.

If it uses if_seq_no and if_primary_term internally by default, why should someone use if_seq_no and if_primary_term parameters explicitly?

If they want the same behaviour for some other reason. There's only so much you can do with a scripted update. For instance I don't know that you can look things up in an external system during an update, so if you wanted to update a document like this you wouldn't be able to do it in a single update. Instead you would need to get the document, calculate the update outside of Elasticsearch, and then insert the updated document back into Elasticsearch using this explicit concurrency control mechanism.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.