gpt4 book ai didi

elasticsearch - 如何使用 Elasticsearch 更新进行原子增量?

转载 作者:行者123 更新时间:2023-11-29 02:48:04 24 4
gpt4 key购买 nike

Elasticsearch 中的这个更新会导致原子增量吗?还是非原子的?

curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script" : "ctx._source.counter += count",
"params" : {
"count" : 1
}
}'

最佳答案

我认为建议的更新脚本<​​em>是原子的,引用Optimistic Concurrency Control讨论不是原子的文档更新(意味着并行更新请求可能会使文档进入“不一致”的意外状态)。

啊,在阅读了更多关于 Partial Updates to Documents 的文档之后我了解到它实际上不是原子的,但它会检查版本号,如果不匹配则失败(因此更新不会悄无声息地丢失,就像 CPU 上的非原子增量一样):

To avoid losing data, the update API retrieves the current _version of the document in the retrieve step, and passes that to the index request during the reindex step. If another process has changed the document between retrieve and reindex, then the _version number won’t match and the update request will fail.

然而,有一个简单的修复方法可以让它像原子增量一样工作:

For many uses of partial update, it doesn’t matter that a document has been changed. For instance, if two processes are both incrementing the page-view counter, it doesn’t matter in which order it happens; if a conflict occurs, the only thing we need to do is reattempt the update.

This can be done automatically by setting the retry_on_conflict parameter to the number of times that update should retry before failing; it defaults to 0.

关于elasticsearch - 如何使用 Elasticsearch 更新进行原子增量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30538437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com