Spring的数据弹性搜索_version,_id等的元数据注释

Mat*_*man 6 java annotations elasticsearch spring-data-elasticsearch

使用@Id注释,我可以添加一个id字段来我的模型对象,当我执行一个查询生成的模型对象将包含elasticsearch的价值_id@Id注释字段中.

但是,我还没弄明白如何获取其他文档元数据,例如_version.我尝试version在我的模型中添加一个字段并用注释注释它@Version但没有发生任何事情并且该字段仍然存在null.

{
    "_index" : "twitter",
    "_type" : "tweet",
    "_id" : "1",
    "_version" : 1,
    "found": true,
    "_source" : {
        "user" : "kimchy",
        "postDate" : "2009-11-15T14:12:12",
        "message" : "trying out Elasticsearch"
    }
}
Run Code Online (Sandbox Code Playgroud)

我指的领域,如_index,_type,_id,_version等...

我特别关心_version因为它用于乐观锁定.

在我看来,如果_id支持那么_version,其他元数据字段也应该以某种方式得到支持.

我刚刚阅读了spring-data-elasticsearch docs,但我找不到任何东西.如果有人知道,请指教.

spring-data-elasticsearch是否支持所有elasticsearch文档元数据字段?如果是这样,怎么样?

此外,如果我能以_version某种方式获得,那么在使用spring-data-elasticsearch时如何将其用于乐观锁定?

谢谢.

can*_*nge 1

据我所知,您所要求的并不存在。然而没有真正的能力来证明这一点。我确实找到了注释列表Spring-data-elasticsearch

http://docs.spring.io/spring-data/elasticsearch/docs/current/api/org/springframework/data/elasticsearch/annotations/package-tree.html

@id 和 @version 都不在该列表中。

我可以找到其他有@version注释的东西,但它们没有Spring-data-elasticsearch

如果你只是在谈论Spring-Data我会向你指出这一点:

http://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/annotation/Version.html

org.springframework.data.annotation

注释类型 版本

@记录@Retention(值=运行时)

@Target(value={FIELD,METHOD,ANNOTATION_TYPE}) 公共@interface

版本 界定用作版本字段的属性以实现实体上的乐观锁定。

自:1.5

作者:帕特里克·瓦西克、奥利弗·吉尔克

这是使用它的一些代码的链接:

http://hantsy.blogspot.com/2013/10/spring-data-new-perspective-of-data.html

不确定这是否是您想要的,但这已经是我所能达到的最接近的了。它用于乐观锁定。