Created
April 7, 2022 06:44
-
-
Save vnkdj5/f8844bc7407055c3b0cf24cc37f27f64 to your computer and use it in GitHub Desktop.
Elastic search bulk add or remove from the array nodejs example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await client.bulk({ | |
index: index, | |
type: "_doc", | |
body: [ | |
{ update: { _id: "1" } }, | |
{ | |
script: { | |
source: `ctx._source.groups.addAll(params.groups); | |
ctx._source.groups= ctx._source.groups.stream().distinct().collect(Collectors.toList());`, | |
lang: "painless", | |
params: { | |
groups: ["admin", "endusers"] | |
} | |
} | |
}, | |
{ update: { _id: "1" } }, | |
{ | |
script: { | |
source: `ctx._source.groups.removeAll(params.groups); | |
ctx._source.groups= ctx._source.groups.stream().distinct().collect(Collectors.toList());`, | |
lang: "painless", | |
params: { | |
groups: ["g2", "g5"] | |
} | |
} | |
} | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment