我正在使用Elasticsearch 5.4,并尝试从嵌套数据类型中删除元素。
我有以下映射:
"links_to_asset": {
"type": "nested",
"properties": {
"note_link_id": {
"type": "long"
},
"user_id": {
"type": "long"
},
"creation": {
"type": "date",
"format": "date_hour_minute_second"
},
"modification": {
"type": "date",
"format": "date_hour_minute_second"
},
"to_asset": {
"type": "integer"
},
"from_asset": {
"type": "integer"
},
"comment": {
"type": "text",
"fields": {
"std": {
"type": "text",
"analyzer": "asset_en_analyzer",
"fields": {
"std": {
"type": "text",
"analyzer": "standard"
}
}
}
}
}
}
}
我在Postman中尝试了以下内容:
本地主机:9200 /资产/书签/ 20976 / _Update相当
{
"script": "ctx._source.links_to_asset.removeAll{it['note_link_id'] == id}",
"params": {
"id": 7343
}
}
但是我收到以下错误:
{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[NvXYDwh][127.0.0.1:9300][indices:data/write/update[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "failed to execute script",
"caused_by": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... .links_to_asset.removeAll{it['links_to_asset.note_ ...",
" ^---- HERE"
],
"script": "ctx._source.links_to_asset.removeAll{it['links_to_asset.note_link_id'] == id}",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "unexpected token ['{'] was expecting one of [{<EOF>, ';'}]."
}
}
},
"status": 400
}
我已经在StackOverflow [1] [2]上提出了几个不同问题的建议,但没有成功。
嵌套对象是有效的,因为我用数据填充它。此外,id
值也有效。
答案 0 :(得分:1)
您尝试编写groovy
脚本,但您在Elasticsearch 5.x中使用的脚本语言为painless
尝试类似
的内容ctx._source.foo = ctx._source.foo.stream().filter(x -> x =='a').collect(Collectors.toList())