gpt4 book ai didi

elasticsearch - 每次在Elasticsearch中更新文档时自动增加字段值

转载 作者:行者123 更新时间:2023-12-02 23:11:11 28 4
gpt4 key购买 nike

这是有效载荷

 {
"videourl": "*****",
"name": "ABCqq",
"description": "AAAnb",
"tags": "#AAAzx",
"uploadedtime": "2020-02-24T05:48:37.527Z",
"uploadedby": "Dr AAAgh",
"thumbnail": "http://",
"duration": "5:32",
"postedby": "AAAdf",
"doctorimage": "AAA12",
"doctorname": "nnn",
}

格式为
{"_index": "rwe",
"_type": "_doc",
"_id": "8wEed3ABcYN_H8khP4hB",
"_score": 1,
"_source": {
"videourl": "*****",
"name": "ABCqq",
"description": "AAAnb",
"tags": "#AAAzx",
"uploadedtime": "2020-02-24T05:48:37.527Z",
"uploadedby": "Dr AAAgh",
"thumbnail": "http://",
"duration": "5:32",
"postedby": "AAAdf",
"doctorimage": "AAA12",
"doctorname": "nnn"
}
}

这是一个文档,我想在每次更新此文档时增加字段的计数值。
我们必须添加名称为 counter_value 的新字段。

预期结果
{"_index": "rwe",
"_type": "_doc",
"_id": "8wEed3ABcYN_H8khP4hB",
"_score": 1,
"_source": {
"videourl": "*****",
"name": "ABCqq",
"description": "AAAnb",
"tags": "#AAAzx",
"uploadedtime": "2020-02-24T05:48:37.527Z",
"uploadedby": "Dr AAAgh",
"thumbnail": "http://",
"duration": "5:32",
"postedby": "AAAdf",
"doctorimage": "AAA12",
"doctorname": "nnn",
"counter_value": 1
}
}

最佳答案

您可以通过脚本增加计数器的数量,请参见herehere。但是,elastic已经有一个version字段。根据您的用例,将version参数添加到查询中就足够了,如here所述:

curl -XGET 'http://localhost:9200/rwe/_search?version=true'

关于elasticsearch - 每次在Elasticsearch中更新文档时自动增加字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60484538/

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