如何获取文档的 _version 当前值

How to fetch current value of _version for a document

如何使用 spring-data-elasticsearch API(s)

获取文档的当前版本值
   {
      "_index" : "foos",
      "_type" : "_doc",
      "_id" : "FQOO93sBMpiRC0Jqlyn8",
      "_version" : 3,
      "result" : "updated",
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "_seq_no" : 84,
      "_primary_term" : 2
    }

在您的实体中定义一个 属性 注释为 @Version:

@Document(indexName="foos")
class Foo {
    @Id private String id;
    @Version private Long version;
    // other properties, getter and setter
}

在获取或搜索结果中返回实体时,此 属性 将填充版本值。