gpt4 book ai didi

elasticsearch - 通过查询更新:如果一项或多项不匹配,则包含多个语句的内联脚本ctx失败?

转载 作者:行者123 更新时间:2023-12-03 00:49:07 24 4
gpt4 key购买 nike

我在下面的内联脚本中使用按查询更新来更新elastic和时间戳approved=true中的lastModifiedDate

POST /limp-access/_update_by_query
{
"query": {
"terms": {
"_id": [
"asdasfasf-laHg5qeld",
"asdfadfdfdsf-asdasd"
]
}
},
"script":{
"source": "ctx._source.approved = true; ctx._source.fields.lastModifiedDate = ['2019-05-21T06:16:05.133Z'];"
}
}

问题是某些文档根本没有此字段 lastModifiedDate。因此,每当遇到此类文档时,它都会失败并使用空指针表达式。有没有办法忽略此类文档并更新找到的文档?

编辑:发布下面我得到的错误:

{ "error": { "root_cause": [ { "type": "script_exception", "reason": "runtime error", "script_stack": [ "ctx._source.fields.lastModifiedDate = ['2019-05-21T06:16:05.133Z'];", " ^---- HERE" ], "script": "ctx._source.approved = true; ctx._source.fields.lastModifiedDate = ['2019-05-21T06:16:05.133Z'];", "lang": "painless" } ], "type": "script_exception", "reason": "runtime error", "script_stack": [ "ctx._source.fields.lastModifiedDate = ['2019-05-21T06:16:05.133Z'];", " ^---- HERE" ], "script": "ctx._source.approved = true; ctx._source.fields.lastModifiedDate = ['2019-05-21T06:16:05.133Z'];", "lang": "painless", "caused_by": { "type": "null_pointer_exception", "reason": null } }, "status": 500 }



期望的是,如果其中一个ID没有字段 fields,我希望它被忽略,并且脚本希望更新找到字段 fields的其余文档。这可能吗?

最佳答案

然后只需像这样更新脚本:

"source": "ctx._source.approved = true; if (ctx._source.fields != null) { ctx._source.fields.lastModifiedDate = ['2019-05-21T06:16:05.133Z'];}"

关于elasticsearch - 通过查询更新:如果一项或多项不匹配,则包含多个语句的内联脚本ctx失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56234124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com