How to stop duplicate data

I am updating my documents in elasticsearch and adding new users, so as an example, suppose I add two new users to my field name "update_field". So now, if I now add these two values ​​to my "update_field" field name, so if I try to insert this again, it will not insert the data again, or I mean that it will not duplicate the data. How can I do this, can someone know how I can write a method to stop duplicate data for elasticsearch, I'm working on PHP

+4
source share
1 answer

Yes, just change the script to this:

"script": "ctx._source.update_field = (ctx._source.update_field + new_value).unique();" 

We basically merge the two lists in groovy, and then with unique() we can remove all duplicates. Another way would be to make a list like Set , which will have the same effect.

+3
source

All Articles