如果在应用更新之前更改了文档,则使用 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
注意:我使用的是 ES 1.5
最佳答案
是的,就是这样。关于 retry and overwrites the value that it was conflict with
声明的澄清:冲突与文档的版本(不是文档中的任意字段)有关,让我们这很清楚,这是 ES 获取文档和实际编写新(更新)文档之间的内部冲突(这两个操作是 _update
操作的一部分)。
并且它不会覆盖与之冲突的值,它是另一个更新操作,只要版本检查正常,就会成功,是的,将更新索引中的文档。
如果您需要确保更新按特定顺序进行,您需要使用version。
关于ElasticSearch - 上次写入获胜行为而不指定版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40232355/