我有以下代码:
"script": {
"lang": "painless",
"source": """
ctx._source.maparray = [
"first" : "Foo",
"last" : "Bar"
]这导致了
"maparray": {
"last": "Bar",
"first": "Foo"
},但是我希望maparray是一个数组。因此,现在基于:
https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-operators-array.html
我试着:
"script": {
"lang": "painless",
"source": """
ctx._source.maparray = new map[]{[
"first" : "Foo",
"last" : "Bar"
]}
""",
"params": {
"key": "numWords"
}
}但我得到了:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... x._source.maparray = new map[]{[\n \"first\" : \"Fo ...",
" ^---- HERE"
],
"script": " ctx._source.maparray = new map[]{[\n \"first\" : \"Foo\",\n \"last\" : \"Bar\"\n]}",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... x._source.maparray = new map[]{[\n \"first\" : \"Fo ...",
" ^---- HERE"
],
"script": " ctx._source.maparray = new map[]{[\n \"first\" : \"Foo\",\n \"last\" : \"Bar\"\n]}",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "invalid sequence of tokens near ['map'].",
"caused_by": {
"type": "no_viable_alt_exception",
"reason": null
}
}
},
"status": 500
}我的语法有什么问题?
发布于 2019-04-26 18:54:49
您正在寻找的实际上是一个map数组。下面是我是如何想出一个使用Ingest Pipeline的示例脚本的。
所需的带脚本的管道
PUT _ingest/pipeline/my-pipeline-id-01
{
"description" : "describe pipeline",
"processors" : [
{
"script" : {
"lang" : "painless",
"inline" : """
ArrayList al = new ArrayList();
Map map = new HashMap();
map.put("first","Foo");
map.put("last", "Bar");
al.add(map);
ctx.maparray = al;
"""
}
}
]
}您可以使用Reindex API测试脚本的工作方式。
重新编制索引脚本
POST _reindex
{
"source": {
"index": "<source_index_name>"
},
"dest": {
"index": "<dest_index_name>",
"pipeline": "my-pipeline-id-01"
}
}请测试以上内容,验证结果,并让我知道它的进展。
希望这能有所帮助!
https://stackoverflow.com/questions/55859865
复制相似问题