结论
通过自己设置一个外部值来判断当前记录的新旧状态,比如你想要version<=5的才进行更新,否则返回失败
?version=5&version_type=external
version_type=external代表你要用外部的值进行判断
version=你的判断值
案例
步骤1:第一次假设原数据version<=5,会返回成功,同时可以看到返回值_version会变成5
website/blog/1?version=5&version_type=external
{
"title": "My first external blog entry",
"text": "Starting to get the hang of this..."
}
返回值
{
"_index": "website",
"_type": "blog",
"_id": "1",
"_version": 5,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 4,
"_primary_term": 1
}
你再请求一次,会报错
{
"error": {
"root_cause": [
{
"type": "version_conflict_engine_exception",
"reason": "[1]: version conflict, current version [5] is higher or equal to the one provided [5]",
"index_uuid": "hqx20LnrTgiOykvXMLw-dQ",
"shard": "0",
"index": "website"
}
],
"type": "version_conflict_engine_exception",
"reason": "[1]: version conflict, current version [5] is higher or equal to the one provided [5]",
"index_uuid": "hqx20LnrTgiOykvXMLw-dQ",
"shard": "0",
"index": "website"
},
"status": 409
}