Append elements to array avoiding duplicates

Hello everyone,

Is there a performant way to append elements to an array avoiding duplicates basically making it work like a Set instead of a List ?

This is the script i'm using, but this will duplicate entries in the array if the array already contains some of the elements. If i run it twice the index will contain [1,2,3,4,5,1,2,3,4,5] instead of [1,2,3,4,5]

"script": {
   "source": "ctx._source.ids.addAll(params.ids)",
   "params": {
     "ids": [1,2,3,4,5]


This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.