我有一个相当基本的要求,我想添加一个对象到一个无痛的查询内更新文档。
这就是我想补充的对象
"memoire": {
"codeActe": "C",
"docType": "M",
"uuid": "added ",
"nonFacturable": false,
"published": false
},
我试过了
POST /csa_encounters/_update_by_query
{
"script":
{ "source": """
ctx._source.memoire.codeActe = "C";
ctx._source.memoire.docType= "M";
ctx._source.memoire.uuid = "added ";
ctx._source.memoire.nonFacturable = false;
ctx._source.memoire.published =false
""",
"lang": "painless"
},
"query": {
"bool" : {
"must" : [
{ "query_string" : { "query" : "140c7646", "fields" : [ "_id" ] } }
]
}
}
}
但是我得到消息null指针异常,因为这个字段当然不存在
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.memoire.codeActe = \"C\";\n ",
" ^---- HERE"
],
...
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
},
"status": 400
如果对象还不存在,我就不知道如何将其创建为新字段。
1条答案
按热度按时间g2ieeal71#
因为这片土地
memoire
文档中不存在。因此,只需在脚本开头添加以下行: