[英]How to update particular field in Elasticsearch index?
在Elasticsearch中,我有以下數據:
"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"
}
}
如何將tId
等於28
Intensity
ea設置為5? 我應該寫哪個更新查詢?
tId = 28的_id為2812 。 所以:
POST traffic/entry/2812/_update
{
"doc" : {
"Intensity" : 5
}
}
資料來源: Elasticsearch參考文檔
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.