Thomas Banderas
Thomas Banderas

Reputation: 1739

Unique constraint on field in spring data elasticsearch

It is possible to create unique constraint in Spring Data Elasticsearch which is equal to @Column(unique = true) in RDBMS?

Unfortunately, @Field annotation does not have Unique param. Perhaps I could use @Id but what if there are other fields like username, email, ...?

Upvotes: 2

Views: 913

Answers (1)

Jaycreation
Jaycreation

Reputation: 2089

Their is no unique constraint in Elasticsearch. You can use your field as an _id like explained in this post : How to create unique constraint in Elasticsearch database?

Or you'll have to create a validator by yourself to test if the value exist with some term query.

Addition: Although the op_type parameter sent to Elasticsearch would provide this feature, there is currently no support for this flag in Spring Data Elasticsearch. There is an issue in Jira which you could upvote.

Upvotes: 2

Related Questions