6

Using the @Id annotation I can add an id field to my model object and when I execute a query the resulting model object will contain the value of the elasticsearch _id in the @Id annotated field.

However, I have yet to figure out how to get other document meta-data such as the _version. I tried adding a version field to my model and annotating 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'm referring to the fields such as _index, _type, _id, _version etc...

I'm especially concerned with _version because that is used for optimistic locking.

It seems to me that if _id is supported then _version and the other meta-data fields should be supported somehow too.

I've just read the spring-data-elasticsearch docs and I can't find anything. If someone knows, please advise.

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

Further, if I can get the _version somehow then how can I use it for optimistic locking when using spring-data-elasticsearch?

Thanks.

1 Answer 1

1

Near as I can tell, what you're asking for doesn't exist. Have no real ability to prove that however. I did find 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 on that list.

I can find other things that have a @version annotation but they aren't Spring-data-elasticsearch.

If you were only talking about Spring-Data I'd point you at 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 Demarcates a property to be used as version field to implement optimistic locking on entities.

Since: 1.5

Author: Patryk Wasik, Oliver Gierke

Here's 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 that's as close as I can come. It is for optimistic locking.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.