elasticsearch中的序列号与版本号

问题描述 投票:0回答:1

我正在阅读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都在增加

因此,当只有一个字段发生变化而另一字段没有变化时,我无法找到情况。两个字段何时会不同?
elasticsearch
1个回答
0
投票
但总而言之,

[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

      对于文档1,_seq_no为0(第一次索引操作)
  • 对于文档2,_seq_no为1(第二索引操作)
  • 对于文档3,_seq_no为2(第三索引操作)
  • © www.soinside.com 2019 - 2024. All rights reserved.