【问题标题】:How to fetch current value of _version for a document如何获取文档的 _version 的当前值
【发布时间】:2021-09-24 12:35:38
【问题描述】:

如何使用 spring-data-elasticsearch API(s) 获取文档的 _version 的当前值

   {
      "_index" : "foos",
      "_type" : "_doc",
      "_id" : "FQOO93sBMpiRC0Jqlyn8",
      "_version" : 3,
      "result" : "updated",
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "_seq_no" : 84,
      "_primary_term" : 2
    }

【问题讨论】:

    标签: spring-data-elasticsearch


    【解决方案1】:

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

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

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

    【讨论】:

    • 索引映射是否会因此而改变,因为我们的应用已经在生产中
    • 没有。版本不会持久化到文档的 _source 中,因此它不会出现在映射中
    猜你喜欢
    • 2016-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    相关资源
    最近更新 更多