Skip to content

Instantly share code, notes, and snippets.

@vnkdj5
Created April 7, 2022 06:44
Show Gist options
  • Save vnkdj5/f8844bc7407055c3b0cf24cc37f27f64 to your computer and use it in GitHub Desktop.
Save vnkdj5/f8844bc7407055c3b0cf24cc37f27f64 to your computer and use it in GitHub Desktop.
Elastic search bulk add or remove from the array nodejs example
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