为什么我的天真Elasticsearch更新经常因文档版本冲突而失败?(Why does my naive Elasticsearch update fail frequently with a do

编程入门 行业动态 更新时间:2024-10-25 22:34:51
为什么我的天真Elasticsearch更新经常因文档版本冲突而失败?(Why does my naive Elasticsearch update fail frequently with a document version conflict?)

我正在使用0.9版本,我有这种非常天真的方法来更新文档,它基本上进行了比较和交换: (仅显示相关代码)

for (int i = 0; i < MAX_RETRY; i++) { GetResponse get = client.prepareGet().execute().actionGet(); // Assume document already exists try { client .prepareIndex() .setId(id) .setSource(newDoc) .setVersion(get.getVersion()) .execute() .actionGet(); // Successfully updated } catch (VersionConflictEngineException e) { continue; //retry } throw UpdateFailedException(); }

该代码适用于大多数更新,但也比我期望的版本冲突更频繁地失败。 奇怪的是,似乎服务器文档在失败时是预期版本的+1。 有什么明显的东西我不见了吗?

我知道Elasticsearch有一个适当的更新功能,但我不能使用这个ATM。

I'm using version 0.9 and I have this very naive approach to update documents, which essentially does a compare and swap: (only relevant code is shown)

for (int i = 0; i < MAX_RETRY; i++) { GetResponse get = client.prepareGet().execute().actionGet(); // Assume document already exists try { client .prepareIndex() .setId(id) .setSource(newDoc) .setVersion(get.getVersion()) .execute() .actionGet(); // Successfully updated } catch (VersionConflictEngineException e) { continue; //retry } throw UpdateFailedException(); }

The code works for most of the updates, but also fails more frequent than I'd expect with version conflict. Curiously, it always seems that the server document is +1 the expected version when it fails. Is there anything obvious that I'm missing?

I understand Elasticsearch has a proper update functionality but I can't use this ATM.

最满意答案

事实证明,由于存在错误,我只是非常频繁地更新文档。

Turns out I was just legitimately updating documents very frequently due to a bug.

更多推荐

本文发布于:2023-04-29 08:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335876.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:天真   冲突   版本   文档   Elasticsearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!