【发布时间】:2018-11-07 14:01:58
【问题描述】:
我刚开始使用 ES,仍然在学习交易技巧!!! 我需要替换/覆盖嵌套对象类型的字段之一。 这是示例文档:
{
"name":"db_ref",
"ref_counter":[
{"ref_name":"test1","count":1},
{"ref_name":"test2","count":2},
{"ref_name":"test3","count":3}
]
}
上述文档的映射:
{
"settings": {
"mappings": {
"test_doc": {
"properties": {
"name": {
"type": "string"
},
"ref_count": {
"type": "nested",
"ref_name": "string",
"count": "long"
}
}
}
}
}
}
我需要更新给定 ref_name 的计数字段值。例如,在上述情况下,如果 ref_name 为“test1”,我希望新的 count 为 500。 我想出了下面的 无痛脚本 来更改 count 值,它执行得很好,没有任何错误,但我没有看到值正在更新。
curl -XPOST "http://localhost:9200/test_type/test_type/test_db/_update" -d '
{"script": "if (ctx._source.ref_counter.ref_name == cur_ref
&& ctx._source.ref_counter.count == cur_count)
{ctx._source.ref_counter.count = new_count };",
"params": {"cur_count": 1,"new_count": 500, "cur_ref": "test1"}}}'
以下是回复:
{"_index":"test_index","_type":"test_type","_id":"test_db","_version":2}
但是当我看到文档时,它仍然具有旧值。
有人可以帮我将计数值更改为新值吗?
【问题讨论】:
标签: elasticsearch elasticsearch-painless