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

时间:2016-04-21 12:27:02

标签: elasticsearch

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

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

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

我当前的行动(在这种情况下,它会创建文档):

{
    update: {
        _index: "index1",
        _type: "interaction",
        _id: item.id
    }
},
{
    script: {
        file: "update-stats",
        lang: "groovy",
        params: {
            newCommentsCount: newRetweetCount,
        }
    },
    upsert: normalizedItem
}

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

谢谢

1 个答案:

答案 0 :(得分:0)

不要使用upsert并使用正常更新。 此外,如果更新时文档不存在,则更新将失败。 它应该适合你。