【发布时间】:2021-02-02 11:52:22
【问题描述】:
我正在尝试使用脚本更新基于 id 的文档字段。该字段的值应为 MAX(field) * 2。例如考虑以下索引
PUT /my-index
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"cost": {
"type": "integer"
}
}
}
}
将仅使用 name 字段值
创建文档POST /my-index/_doc/sp1
{
"name": "Shirt"
}
创建此文档后,我想将 cost 值更新为该索引中成本的最大值 (max(cost) * 2)。我使用更新 API 尝试了这个逻辑,如下所示
POST /my-index/_doc/sp1
{
"script" : {
"source": "ctx._source.cost = Math.max(doc['cost'].value) * 2"
}
}
但我无法做到这一点。遇到如下错误
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "static method [java.lang.Math, max/1] not found"
}
如何实现这个场景
【问题讨论】:
标签: elasticsearch