使用elasticsearch.js (node.js) SDK,我们可以使用client.index({ ... })来插入文档(如果不存在则插入,否则更新)。
但是,如果我只想更新一个特定的字段,例如:
client.updateByQuery({
index: 'test',
body: {
query: { match: { _id: '1' } },
script: { inline: 'ctx._source.hello = "world"' }
}
})现在,我想创建一个id为1的文档,如果它不存在,并将其字段hello设置为world,或者如果id为1的文档存在,则将其hello字段更新为world。这个是可能的吗?多么?
发布于 2019-10-22 14:45:39
您可能正在寻找update API with doc as update。使用方法如下:
POST test/_update/1
{
"doc":{
"hello": "world"
},
"doc_as_upsert": true
}https://stackoverflow.com/questions/58498230
复制相似问题