在Elasticsearch中我有以下数据:
narrow_cast
如果"hits": [
{
"_index": "traffic",
"_type": "entry",
"_id": "922",
"_score": 1,
"_source": {
"Intensity": 0,
"tId": "9"
}
},
{
"_index": "traffic",
"_type": "entry",
"_id": "2812",
"_score": 1,
"_source": {
"Intensity": 0,
"tId": "28"
}
}
等于Intensity
,我如何设置tId
等于5?我应该写哪个更新查询?
答案 0 :(得分:1)
tId = 28的 _id 为 2812 。所以:
POST traffic/entry/2812/_update
{
"doc" : {
"Intensity" : 5
}
}
答案 1 :(得分:0)
client.updateByQuery({
index : 'traffic',
type : 'entry',
body : {
query : {
match : {
tId : 28
}
},
script :
{'inline':
'ctx._source.Intensity = params["Intensity"];',
lang : 'painless',
params : {Intensity: 5 }
}
}
}, (err, res) => {
if (err) {
reject(err);
} else {
resolve(res);
}
});
对于启用脚本,您应该在elasticsearch.yaml文件中包含script.inline: true