Spring -data-elasticsearch metadata annotations for _version, _id, etc.

Using the @Id annotation, I can add an id field to my model object and when the query is executed, the resulting model object will contain the elasticsearch _id in the annotated @Id field.

However, I have yet to figure out how to get other document metadata, such as _version . I tried to add the version field to my model and annotate it with the @Version annotation, but nothing happened and the field remained null .

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

I mean fields like _index , _type , _id , _version , etc.

I am particularly concerned about _version because it is used for optimistic locking.

It seems to me that if _id supported, then _version and other metadata fields should also be supported.

I just read the spring -data-elasticsearch docs and I can't find anything. If anyone knows, please let me know.

Are all metadata fields of an elasticsearch document supported in spring-data-elasticsearch? If so, how?

Also, if I can somehow get _version , then how can I use it to optimize the lock when using spring -data-elasticsearch?

Thanks.

+6
source share
1 answer

Nearby, as I can judge, what you are asking for does not exist. Not having a real opportunity to prove it. I found a list of annotations for Spring-data-elasticsearch :

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

Neither @id nor @version are included in this list.

I can find other things with @version annotation, but they are not Spring-data-elasticsearch .

If you were only talking about Spring-Data , I would point you to this:

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

org.springframework.data.annotation

Annotation Type Version

@ Documented @Retention (value = RUNTIME)

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

Version Delimits a property that will be used as the version field to implement optimistic locking for entities.

Since: 1.5

Posted by Patrick Vasik, Oliver Girke

Here is a link to some code using it:

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

Not sure if this is what you want, but as close as I can come. This is for optimistic blocking.

+1
source

Source: https://habr.com/ru/post/979823/


All Articles