无法通过查询脚本对字符串字段执行弹性搜索更新。这是我的查询
curl -X POST "http://localhost:9200/z5-purchase-orders/_update_by_query?pretty" -H 'Content-Type: application/json' -d'
{
"script": {
"source": "ctx._source.facility_name = VCU",
"lang": "painless"
},
"query": {
"bool" : {
"must" : [
{ "match" : {"facility_id" : 0} },
{ "match" : {"customer_id" : 1002} }
]
}
}
}
'我对整数字段执行了相同的查询。它工作得很好,字符串会导致错误。
{
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"... ._source.facility_name = VCU",
" ^---- HERE"
],
"script" : "ctx._source.facility_name = VCU",
"lang" : "painless"
}
],
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"... ._source.facility_name = VCU",
" ^---- HERE"
],
"script" : "ctx._source.facility_name = VCU",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Variable [VCU] is not defined."
}
},
"status" : 400
}请通过查询帮助进行此字符串更新。我使用弹性搜索版本7。
发布于 2022-04-21 15:57:50
要修复该错误,只需对值VCU进行字符串化
"ctx._source.facility_name = 'VCU'"如果你在那之后仍然有一个错误,它将是另一个错误,你可以自由地分享它。
发布于 2022-04-22 05:05:19
在转义角色之后,效果很好。
"script": {
"source": "ctx._source.facility_name = \"VCU\"",
"lang": "painless"
},https://stackoverflow.com/questions/71956366
复制相似问题