elasticsearch 如何使用groovy脚本反转elasticsearch文档中数组中的所有字符串?,elasticsearch,groovy,elasticsearch,Groovy" /> elasticsearch 如何使用groovy脚本反转elasticsearch文档中数组中的所有字符串?,elasticsearch,groovy,elasticsearch,Groovy" />

elasticsearch 如何使用groovy脚本反转elasticsearch文档中数组中的所有字符串?

elasticsearch 如何使用groovy脚本反转elasticsearch文档中数组中的所有字符串?,elasticsearch,groovy,elasticsearch,Groovy,我有一份elasticsearch文档 { “_索引”:“测试索引”, “_type”:“testtype”, “_id”:“doc1”, “_版本”:1, “发现”:正确, “_来源”:{ “数组”:[ “abc”, “def”, “ghi” ] } } 如何反转文档中数组中的所有字符串?我尝试将更新api与以下脚本一起使用 temp=[];对于(字符串项:ctx.\u source.array)temp请尝试以下操作 temp=[]; ctx._source.array.each{

我有一份elasticsearch文档

{
“_索引”:“测试索引”,
“_type”:“testtype”,
“_id”:“doc1”,
“_版本”:1,
“发现”:正确,
“_来源”:{
“数组”:[
“abc”,
“def”,
“ghi”
]
}
}

如何反转文档中数组中的所有字符串?我尝试将更新api与以下脚本一起使用

temp=[];对于(字符串项:ctx.\u source.array)temp请尝试以下操作

temp=[];

ctx._source.array.each{

    it -> temp.add(it.reverse())
}

ctx._source.array = temp

抛出异常是因为groovy脚本中使用了reverse()函数。我同意它是一个有效的groovy脚本。但是,当我给出与elasticsearch更新api相同的脚本时,我得到了上面提到的异常。然后clouser中的值不是字符串,然后将其转换为toString(),并尝试对其进行反向操作。希望这有帮助
Bulk request failure, id: [doc4], message: ElasticsearchIllegalArgumentException[failed to execute script]; nested: GroovyScriptCompilationException[MultipleCompilationErrorsException[startup failed:
General error during canonicalization: Method calls not allowed on [java.lang.String]
temp=[];

ctx._source.array.each{

    it -> temp.add(it.reverse())
}

ctx._source.array = temp