Convert groovy script to painless ( collect)

Hell i have this script with collection it's working in groovy But I can't find if there's a way to do this with painless ?

GET exemple/_search
{
"script_fields" : {
"checks" : {
"script" : {
"lang": "groovy",
"inline":
"_source.mebers.collect{it.check}"
}
}
}
}

Hi @radi,

the collect method still exists on collections, but the lambda function syntax is similar to the java sytax, i.e.

GET example/_search
{
  "script_fields": {
    "checks": {
      "script": {
        "lang": "painless",
        "source": "doc['members'].collect(member -> member.check)"
      }
    }
  }
}

thenk's for your replay ,
I tested this solution but I have this error
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "[script] unknown field [source], parser not found"
}
],
"type": "illegal_argument_exception",
"reason": "[script] unknown field [source], parser not found"
},
"status": 400
}

Which version of the Elastic Stack are you running?

Elastic Stack version 5.4.0

In that version the key is still called inline, so this should work:

GET example/_search
{
  "script_fields": {
    "checks": {
      "script": {
        "lang": "painless",
        "inline": "doc['members'].collect(member -> member.check)"
      }
    }
  }
}

already test , and i have this error

"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "invalid sequence of tokens near ['->'].",

I need to use _source ( like in groovy )
but i read this now !
[https://github.com/elastic/elasticsearch/issues/20068](http://painless _source )
_source is definitely a controversial issue, but as of right now, _source is only supported in update scripts within Painless.

hm, this works for me in Kibana 5.4.3:

GET example/_search
{
  "script_fields": {
    "checks": {
      "script": {
        "lang": "painless",
        "inline": "params._source['members'].collect(member -> member.check)"
      }
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.