我正在阅读elasticsearch-7.4的概念,我了解了两个领域。_seq_no
和_version
。
根据文档:
版本
Returns a version for each search hit.
序列号和主要术语
Returns the sequence number and primary term of the last modification to each search hit.
但是,对于与文档何时两者不同或相同,这并没有清除任何相关内容。
我创建了索引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都在增加。
关于使用UPDATE API
进行部分更新,POST /test/_doc/2/_update
{
"doc" : {
"base_price" : 10000
}
}
在这种情况下,。 因此,当只有一个字段发生变化而另一字段没有变化时,我无法找到情况。两个字段何时会不同?_ seq_no和_version都在增加
[version
是一个序列号,用于计算文档更新的时间]
_seq_no
是一个序号,用于计算索引上发生的操作数version
和_seq_no
将不同。POST test/_doc/_bulk
{"index": {}}
{"test": 1}
{"index": {}}
{"test": 2}
{"index": {}}
{"test": 3}
在响应中,您将在下面获得有效负载。
{ "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
_seq_no
为0(第一次索引操作)_seq_no
为1(第二索引操作)_seq_no
为2(第三索引操作)