ElasticSearch - 上次写入获胜行为而不指定版本

标签 elasticsearch

如果在应用更新之前更改了文档,则使用 update API 对文档进行部分更新似乎会失败:

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.

然后它继续说您可以提供 retry_on_conflict 如果确实发生冲突,它将重试写入:

For many uses of partial update, it doesn’t matter that a document has been changed...

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.

因此,如果我将 update API 与 say 3 的 retry_on_conflict 一起使用,而不提供 _version 字段,则 ES 将在内部失败一次(如果确实发生冲突),然后重试并覆盖与之冲突的值?

看起来是这样,因为

...the update API adopts a last-write-wins approach by default

来源:https://www.elastic.co/guide/en/elasticsearch/guide/current/partial-updates.html#_updates_and_conflicts

注意:我使用的是 ES 1.5

最佳答案

是的,就是这样。关于 retry and overwrites the value that it was conflict with 声明的澄清:冲突与文档的版本(不是文档中的任意字段)有关,让我们这很清楚,这是 ES 获取文档和实际编写新(更新)文档之间的内部冲突(这两个操作是 _update 操作的一部分)。

并且它不会覆盖与之冲突的值,它是另一个更新操作,只要版本检查正常,就会成功,是的,将更新索引中的文档。

如果您需要确保更新按特定顺序进行,您需要使用version

关于ElasticSearch - 上次写入获胜行为而不指定版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40232355/

相关文章:

ruby-on-rails - 提交Elasticsearch时如何在搜索框中保留搜索框输入

elasticsearch - 需要说明Logstash配置中使用的sql_last_value

amazon-web-services - Dynamodb流无需其他中间层即可直接进入Elasticsearch

java - IndexNotFoundException[没有这样的索引]

elasticsearch - Kibana仪表板显示了空的可视化,但可视化本身有效

elasticsearch - 如何根据主机将StormCrawler内容发送到多个Elasticsearch索引?

elasticsearch - Elasticsearch将长序列字符串与模糊查询进行比较

elasticsearch - kibana在发现选项卡中未显示黄色标记的Elasticsearch索引

elasticsearch - 将FunctionScore/FieldValueFactor添加到MultiMatch查询

Elasticsearch 平均日期直方图桶