Elasticsearch中的序列号与版本号 [英] sequence number vs version number in elasticsearch
问题描述
我正在阅读elasticsearch-7.4的概念,并且了解了两个领域。
_seq_no
和 _version
。
I am reading the concepts of elasticsearch-7.4 and I got to know about two fields.
_seq_no
and _version
.
根据文档:
版本
Returns a version for each search hit.
序列号和主术语
Returns the sequence number and primary term of the last modification to each search hit.
但是并没有清除与文档何时将不同或相同的任何内容。
But it is not clearing anything related to when they both will be different or same for a document.
我创建了索引 test
PUT /test/_doc/_mapping
{
"properties": {
"total_price" : {
"type": "integer"
},
"final_price": {
"type": "integer"
},
"base_price": {
"enabled": false
}
}
}
我正在使用 PUT API
。
PUT /test/_doc/2
{
"total_price": 10,
"final_price": 10,
"base_price": 10
}
在这种情况下, _seq_no和_version都在增加 。
Both _seq_no and _version are increasing in this case.
使用 UPDATE API
进行部分更新时,
POST /test/_doc/2/_update
{
"doc" : {
"base_price" : 10000
}
}
_seq_no和_version都在增加 在这种情况下也是如此。
Both _seq_no and _version are increasing in this case too.
因此,当只有一个字段发生变化而另一字段没有变化时,我无法找到情况。
两个字段何时会有所不同?
So, I am unable to find the case when only one field is changing but the other is not.
When will both the fields be different?
推荐答案
ES 6.0.0中引入了序列号。在该版本发布之前,博客文章。
Sequence numbers have been introduced in ES 6.0.0. Just before that release came out, they were very well explained in this blog article.
但总而言之,
-
version
是一个序列号,用于计算文档更新的时间 -
_seq_no
是计算索引上发生的操作次数的序列号
version
is a sequential number that counts the number of time a document was updated_seq_no
is a sequential number that counts the number of operations that happened on the index
因此,如果您创建第二个文档,您会看到版本
和 _seq_no
将有所不同。
So if you create a second document, you'll see that version
and _seq_no
will be different.
让我们创建三个文档:
POST test/_doc/_bulk
{"index": {}}
{"test": 1}
{"index": {}}
{"test": 2}
{"index": {}}
{"test": 3}
在响应中,您将在下面获得有效载荷。
In the response, you'll get the payload below.
{
"took" : 166,
"errors" : false,
"items" : [
{
"index" : {
"_index" : "test",
"_type" : "_doc",
"_id" : "d2zbSW4BJvP7VWZfYMwQ",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "test",
"_type" : "_doc",
"_id" : "eGzbSW4BJvP7VWZfYMwQ",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "test",
"_type" : "_doc",
"_id" : "eWzbSW4BJvP7VWZfYMwQ",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1,
"status" : 201
}
}
]
}
如您所见:
- 对于所有文档,版本均为1
- 对于文档1 ,
_seq_no
为0(第一次索引操作) - 对于文档2,
_seq_no
是1(第二索引操作) - 对于文档3,
_seq_no
是2(第三索引操作)
- for all documents, version is 1
- for document 1,
_seq_no
is 0 (first index operation) - for document 2,
_seq_no
is 1 (second index operation) - for document 3,
_seq_no
is 2 (third index operation)
这篇关于Elasticsearch中的序列号与版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!