我正在使用update_by_query和以下正文:
POST /documents/_update_by_query
{
"script":{
"source":"for(int i = 0;i < ctx._source.fields.size();i++){for (int j = 0; j < params.field_uid.size();j++){ if(params.field_uid[j].type == \"group\" ){ } else{ if(ctx._source.fields[i].uid == params.field_uid[j].uid){ ctx._source.fields.remove(i);} } }}",
"params":{
"field_uid":[{"uid":"number","type":"number"},{"uid":"test","type":"group"}]
}
},
"query": {
"term": {
"name": "test"
}
}
}
它给了我像Extraneous if声明。这是我收到的错误消息:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... s.field_uid.size();j++){ if(params.field_uid[j].ty ...",
" ^---- HERE"
],
"script": "for(int i = 0;i < ctx._source.fields.size();i++){for (int j = 0; j < params.field_uid.size();j++){ if(params.field_uid[j].type == 100 ){ } else{ if(ctx._source.fields[i].uid == params.field_uid[j].uid){ ctx._source.fields.remove(i);} } }}",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... s.field_uid.size();j++){ if(params.field_uid[j].ty ...",
" ^---- HERE"
],
"script": "for(int i = 0;i < ctx._source.fields.size();i++){for (int j = 0; j < params.field_uid.size();j++){ if(params.field_uid[j].type == 100 ){ } else{ if(ctx._source.fields[i].uid == params.field_uid[j].uid){ ctx._source.fields.remove(i);} } }}",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Extraneous if statement."
}
},
"status": 500
}
任何人都可以帮助我吗? 这有什么不对?
答案 0 :(得分:1)
写入的if
语句没有执行任何操作,并且因为ES导致extraneous if statement
错误而无关紧要。
将其删除并相应更新条件,如下所示。
for(int i = 0;i < ctx._source.fields.size();i++){ for (int j = 0;j <
params.field_uid.size();j++){ if(params.field_uid[j].type != \"group\"
&& ctx._source.fields[i].uid == params.field_uid[j].uid){
ctx._source.fields.remove(i);}}}