我是Elasticsearch堆栈的新手...每当我尝试在Kibana Dev Tool Console中执行以下查询时,始终遇到以下提到的错误
在Kibana控制台中执行
POST employees-details/_update_by_query
{
"query": {
"match": {
"EmpName": "Arvind"
}
},
"script": {
"source": "ctx._source.Address.add(params.tag)",
"lang": "painless",
"params": {
"tag":{
"AddressID":144,
"AddressNumber":458
}
}
}
}
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "dynamic method [java.util.HashMap, add/1] not found"
}
[
{
"_index" : "employees-details",
"_type" : "_doc",
"_id" : "101",
"_score" : 1.0,
"_source" : {
"EmpUserID" : 101,
"Gender" : "Male",
"EmpName" : "John",
"Age" : 35
}
},
{
"_index" : "employees-details",
"_type" : "_doc",
"_id" : "106",
"_score" : 1.0,
"_source" : {
"EmpUserID" : 106,
"Address" : {
"AddressNumber" : 201,
"AddressID" : 200
},
"Gender" : "Male",
"EmpName" : "Arvind",
"Age" : 30
}
}
]
提前致谢 :)
最佳答案
由于Address
是散列,因此您不能使用add()
方法(适用于数组,列表等集合)。相反,您需要先将Address
转换为列表,然后调用add()
:
POST employees-details/_update_by_query
{
"query": {
"match": {
"EmpName": "Arvind"
}
},
"script": {
"source": "if (!(ctx._source.Address instanceof Collection)) {ctx._source.Address = [ctx._source.Address];} ctx._source.Address.add(params.tag)",
"lang": "painless",
"params": {
"tag":{
"AddressID":144,
"AddressNumber":458
}
}
}
}
关于elasticsearch - 在kibana控制台中不断收到此错误 “dynamic method [java.util.HashMap, add/1] not found”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/64604096/