# 请求
POST/my_index_1/_doc/1?if_seq_no=0&if_primary_term=1{"content":"探索Elasticsearch版本控制的最佳实践。"}# 返回
{"error":{"root_cause":[{"type":"version_conflict_engine_exception","reason":"[1]: version conflict, required seqNo [0], primary term [1]. current document has seqNo [1] and primary term [1]","index_uuid":"yQKxbXSMTu-S2w28Quakjw","shard":"0","index":"my_index_1"}],"type":"version_conflict_engine_exception","reason":"[1]: version conflict, required seqNo [0], primary term [1]. current document has seqNo [1] and primary term [1]","index_uuid":"yQKxbXSMTu-S2w28Quakjw","shard":"0","index":"my_index_1"},"status":409}
一个常见的场景是使用其它数据库作为主要的数据存储,使用 Elasticsearch 做数据检索,这意味着主数据库的所有更改发生时都需要被复制到 Elasticsearch,如果多个进程负责这一数据同步,你可能遇到类似于之前描述的并发问题。此时需要控制版本号大于 es 版本号。
(2)三种控制方式对比
乐观并发控制(_version):老版本 es 使用,传入的版本号必须和 es 数据版本号一致。
乐观并发控制(if_seq_no和if_primary_term):新版本 es 使用,传入的参数必须和 es 数据一致。
外部版本控制:通过version_type=external&version=版本号参数来实现。但是这里的版本号必须是大于 es 数据中的版本号,小于等于会报错。
(3)低版本更新文档
当外部版本号小于等于 es 版本号时,更新失败。
# 请求
POST/my_index_1/_doc/1?version_type=external&version=3{"content":"探索Elasticsearch版本控制的最佳实践。222"}# 返回
{"error":{"root_cause":[{"type":"version_conflict_engine_exception","reason":"[1]: version conflict, current version [3] is higher or equal to the one provided [3]","index_uuid":"yQKxbXSMTu-S2w28Quakjw","shard":"0","index":"my_index_1"}],"type":"version_conflict_engine_exception","reason":"[1]: version conflict, current version [3] is higher or equal to the one provided [3]","index_uuid":"yQKxbXSMTu-S2w28Quakjw","shard":"0","index":"my_index_1"},"status":409}
执行./configure命令出现如下奇怪的错误,百思不得姐: ./configure命令的日志文件为config.log,发生错误时,该文件的内容:
This file contains any messages produced by compilers while
running configure, to aid d…