我有一个弹性搜索文档
{
"_index": "testindex",
"_type": "testtype",
"_id": "doc1",
"_version": 1,
"found": true,
"_source": {
"array": [
"abc",
"def",
"ghi"
]
}
}
如何反转文档中数组中的所有字符串?我尝试使用带有以下脚本的更新api
temp = []; for(String item : ctx._source.array) temp << item.reverse(); ctx._source.array = temp;
在java中更新api:
new org.elasticsearch.action.update.UpdateRequest(index, type, docId).script(script);
我得到一个异常,比如脚本中不允许的方法调用。
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]