gpt4 book ai didi

elasticsearch - 用于UPDATE的ElasticSearch脚本问题

转载 作者:行者123 更新时间:2023-12-03 01:56:59 25 4
gpt4 key购买 nike

我正在尝试使用以下脚本更新数组值

POST /book/123/_update
{
"script": "foreach (item : ctx._source.BookAvailability) { if (item['BookPublishDate'] == publish_date) { item['Price'] = start_price;} }",
"params": {
"publish_date":"2016-09-09T12:00:00",
"start_price": "123"}
}

但是我遇到以下错误,
{
"error": "ElasticsearchIllegalArgumentException[failed to execute script]; nested: GroovyScriptExecutionException[MissingMethodException[No signature of method: a7119b66f45277239600593efdc39002b301e293.foreach() is applicable for argument types: (java.util.LinkedHashMap, a7119b66f45277239600593efdc39002b301e293$_run_closure1) values: [[item:[[Price:189.000, BookCategoryID:e62dcda3-579a-4936-902c-05e1bcc97e3e, ...], ...]], ...]\nPossible solutions: each(groovy.lang.Closure)]]; ",
"status": 400
}

我的模式就是这样,
{
"BookID" : "123",
"BookName": "abcd",
.
.
.
"BookAvailability" : [
{
"BookCategoryID" : "e62dcda3-579a-4936-902c-05e1bcc97e3e",
"Price": "189.00",
"BookPublishDate": "2016-09-09T12:00:00"
.
.
.
}
]
}

最佳答案

试试这个脚本

ctx._source.BookAvailability.findAll { it['BookPublishDate'] == publish_date }.each { it['Price'] = start_price }

它首先选择 BookPublishDatepublish_date参数匹配的所有元素,然后遍历匹配项并将 Price设置为 start_price

关于elasticsearch - 用于UPDATE的ElasticSearch脚本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35883673/

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