Elasticsearch批量索引 - 仅在存在时更新

Ale*_*exD 6 elasticsearch

我正在使用Elasticsearch批量索引来更新文档的某些统计信息,但可能会发生我尝试更新的文档不存在 - 在这种情况下我希望它什么都不做.

在这种情况下,我不希望它创建文档.

我没有在文档中找到任何内容,或者可能错过了它.

我当前的操作(在这种情况下,它创建文档):

{
    update: {
        _index: "index1",
        _type: "interaction",
        _id: item.id
    }
},
{
    script: {
        file: "update-stats",
        lang: "groovy",
        params: {
            newCommentsCount: newRetweetCount,
        }
    },
    upsert: normalizedItem
}
Run Code Online (Sandbox Code Playgroud)

如何仅在文档存在时更新文档,否则什么都没有?

谢谢

Vin*_*han 0

不要使用 upsert 并使用正常更新。另外,如果更新时文档不存在,更新也会失败。到此为止,它应该很适合你。