'ElasticSearch _update_by_query filter elements of array

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);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source