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

问题描述 投票:0回答:1

这是有效载荷

 {
  "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
}
}
node.js elasticsearch amazon-elastic-beanstalk
1个回答
0
投票

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

curl -XGET 'http://localhost:9200/rwe/_search?version=true'
© www.soinside.com 2019 - 2024. All rights reserved.