spring-data-jest icon indicating copy to clipboard operation
spring-data-jest copied to clipboard

Possibility to use an internal type of @Version provided by Elasticsearch

Open ausov opened this issue 8 years ago • 1 comments

How can we use internal versioning of Elasticsearch?

Elsticsearch has a possibility to use internal (managed by ES) or external (managed in code) types of version to implement optimistic locking (https://www.elastic.co/blog/elasticsearch-versioning-support). Currently, if an entity field marked with @org.springframework.data.annotation.Version the external version type is always used.

On the other hand, the Spring Data Rest also uses @Version mechanism to implement ETag and If-Match headers handling. This means that if we want to use this mechanism, we're forced to use ES optimistic locking and external ES versioning.

So, it would be great if we can specify which version mechanism we want to use. Note, same issue is with the spring-data-elasticsearch.

Possible solution: Introduce a new optional annotation on a version field or, probably more appropriate, on a repository to specify a version type, e.g. @VersionType(EXTERNAL). For example:

@VersionType(EXTERNAL)
@Version
private Long version = 0L;
...

or on repository class:

@VersionType(EXTERNAL)
public class MyRepo extends ElasticsearchReporitory ...

Workaround: implement a custom repo taking care of version increment.

ausov avatar Sep 18 '16 21:09 ausov

Added issue in spring-data-elasticsearch: https://jira.spring.io/browse/DATAES-295

ausov avatar Sep 18 '16 21:09 ausov