0

I am persisting data through elasticsearch and even though the data is persisted multiple times, it will be stored with auto-generated different string id values. I want multiple entries of the same data to be avoided from being persistence by making the email field as the primary key. How could I achieve this in elasticsearch

{
  "email":"[email protected]",
  "name": "abc"
}

return client.prepareIndex(Constants.INDEX_NAME, Constants.TYPE)
            .setSource(XContentFactory.jsonBuilder()
            .startObject()
                .field("email", email)
                .field("name", name)
            .endObject())
            .get();
2
  • 1
    stackoverflow.com/questions/21461269/… You need to set then your email as the _id Field. Commented Mar 22, 2019 at 10:08
  • If you need to keep your id, consider upsert by querry the email field. Commented Mar 22, 2019 at 10:47

0

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.