Based on this answer, it's clearly to say:
primary_term
to uniquely determine the version on the index;However as a user, is there any difference between version=1&version_type=external
and if_seq_no=0&if_primary_term=1
to achieve concurrency control?
My understanding is that:
to achieve "external" concurrency control, if_seq_no=0&if_primary_term=1
can be a little more inconvenient since we have to record two fields at the same time in DB while we only need to record version
as to version=1&version_type=external
.
as for "internal" concurrency control, if_seq_no=0&if_primary_term=1
will improve the parallelism level while version
is comparably worse.
Are these two conclusions right? If right, why specifically?
I did some simple experiments in ES 7.4.2 as follows:
POST test/_bulk
{"index": { "_id": 1 }}
{"test": 1}
{"index": { "_id": 2 }}
{"test": 2}
PUT test/_doc/1?version=1&version_type=external&error_trace=true
{
"test": 1
}
GET test/_doc/1
PUT test/_doc/1?if_seq_no=0&if_primary_term=1&error_trace=true
{
"test": 1
}
Based on this old post Elasticsearch Versioning Support, I see that _version
is used in ES for concurrency control.
While in Breaking changes in 6.7, I might just quote here.
internal version may not uniquely identify a document’s version if an indexed document wasn’t fully replicated when a primary fails. As such it is unsafe to use for optimistic concurrency control, is deprecated and the option will no longer be available in Elasticsearch 7.0.0. Please use the if_seq_no and if_primary_term parameters instead.
So basically the answers are:
if_seq_no=0&if_primary_term=1
as the only option.