0

Problem: I need to remove numbers > 25000000 from array in elasticsearch using _update_by_query.

curl -XPOST 'http://127.0.0.1:9200/mydb/_update_by_query' --header 'Content-Type: application/json'  --data '
{"query": {
 "range": {
 "multiAccounts": { "gte": 25000000 } } },
 "script": {"source": "ctx._source.multiAccounts = ctx._source.multiAccounts;"}
}'

Insted of ctx._source.multiAccounts = ctx._source.multiAccounts; I need somethig like:

ctx._source.multiAccounts = ctx._source.multiAccounts.filter(el < 25000000);
1
  • Can you show a sample document please? Commented Feb 2, 2022 at 17:06

1 Answer 1

1

Since Painless relies on Java (and if multiAccounts is an array in your source document), then you can use streams, like this:

ctx._source.multiAccounts = ctx._source.multiAccounts.stream().filter(el -> el > 25000000).collect(Collectors.toList());
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, but el < 25000000 in my case. Big thanks!

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.