Error: org.codehaus.groovy.reflection.CachedMethod can not access a member of class groovy.lang.Closure

I'm trying to execute this groovy script:

Working script in Groovy Console:

def m1 = [ a:[1, 1, 1], b:[1, 1, 1], d:[1,1,1] ]
def m2 = [ b:[1, 1, 1], c:[1, 1, 1] ]

def newMap = [m1,m2]*.keySet().flatten().unique().collectEntries {
  [ (it): [m1,m2]*.get( it ).findAll().transpose()*.sum() ]
}

Result: [a:[1, 1, 1], b:[2, 2, 2], d:[1, 1, 1], c:[1, 1, 1]]

Running the same script in Elasticsearch:

{
  "script": "ctx._source.fn=[ctx._source.fn,fn]*.keySet().flatten().unique().collectEntries {[ (it): [ctx._source.fn,fn]*.get( it ).findAll().transpose()*.sum() ]}", 
  "params": {
      "fn": {
        "test1": [2],  
        "test2": [2,2]  
      }
},
  "upsert": {
      "fn": {
        "test1": [2],  
        "test2": [2,2] 
      }
}
}     

The first time upsert works. But the second time the script fails with this error:

{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[node_name][node_host_name/node_ip:9300][indices:data/write/update[s]]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "failed to execute script",
    "caused_by": {
      "type": "script_exception",
      "reason": "failed to run inline script [ctx._source.fn=[ctx._source.fn,fn]*.keySet().flatten().unique().collectEntries {[ (it): [ctx._source.fn,fn]*.get( it ).findAll().transpose()*.sum() ]}] using lang [groovy]",
      "caused_by": {
        "type": "privileged_action_exception",
        "reason": null,
        "caused_by": {
          "type": "illegal_access_exception",
          "reason": "Class org.codehaus.groovy.reflection.CachedMethod can not access a member of class groovy.lang.Closure$1 with modifiers \"public\""
        }
      }
    }
  },
  "status": 400
}

I tried doing this: https://github.com/ywelsch/elasticsearch/commit/87a13f88faadbfd27f032e24703bf8b96568a693

The java.security.policy file already has permission
java.security.policy=/opt/pw/pronto/conf/java.security.policy

grant {
      // Allow everything for now
      permission java.security.AllPermission;
 };

How to proceed running this groovy script?

groovy findAll() method is causing this issue. Is there any alternative for findAll() ?

This is a known bug related to Groovy cached closure class inspection

Thank you!

I replaced the " findAll() " method to "minus(null)". and things works fine now.

So now my script looks like :

"script": "ctx._source.fn=[ctx._source.fn,fn]*.keySet().flatten().unique().collectEntries { [ (it): [ctx._source.fn,fn]*.get( it ).minus(null).transpose()*.sum()]}"