2

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, ...?

1 Answer 1

2

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.

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.