Elasticsearch之CURL命令的version控制
生活随笔
收集整理的這篇文章主要介紹了
Elasticsearch之CURL命令的version控制
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
?
普通關系型數據庫使用的是(悲觀并發控制(PCC))
當我們在修改一個數據前先鎖定這一行,然后確保只有讀取到數據的這個線程可以修改這一行數據
ES使用的是(樂觀并發控制(OCC))
ES不會阻止某一數據的訪問,然而,如果基礎數據在我們讀取和寫入的間隔中發生了變化,更新就會失敗,這時候就由程序來決定如何處理這個沖突。它可以重新讀取新數據來進行更新,又或者將這一情況直接反饋給用戶。
ES如何實現版本控制(使用es內部版本號)
1)首先得到想要修改的文檔,獲取版本version號
curl -XGET http://master:9200/zhouls/user/2 [hadoop@master elasticsearch-2.4.0]$ curl -XGET http://master:9200/zhouls/user/2 {"_index":"zhouls","_type":"user","_id":"2","_version":1,"found":true,"_source":{"name" : "john" , "age" : 28}}[hadoop@master elasticsearch-2.4.0]$ [hadoop@master elasticsearch-2.4.0]$ [hadoop@master elasticsearch-2.4.0]$?
?
?
?
?
?
?
?
?
?
2)在執行更新操作的時候把版本號傳過去
curl -XPUT http://master:9200/zhouls/user/2?version=1 -d '{"name" : "john1" , "age" : 29}'?
[hadoop@master elasticsearch-2.4.0]$ curl -XPUT http://master:9200/zhouls/user/2?version=1 -d '{"name" : "john1" , "age" : 29}' {"_index":"zhouls","_type":"user","_id":"2","_version":2,"_shards":{"total":2,"successful":2,"failed":0},"created":false}[hadoop@master elasticsearch-2.4.0]$?
?
?
?
?
?
?
?
?
?
?
?
curl -XPOST http://master:9200/zhouls/user/2/_update?version=2 -d '{"doc" :{"age" : 30}}'?
[hadoop@master elasticsearch-2.4.0]$ curl -XPOST http://master:9200/zhouls/user/2/_update?version=2 -d '{"doc" :{"age" : 30}}' {"_index":"zhouls","_type":"user","_id":"2","_version":3,"_shards":{"total":2,"successful":2,"failed":0}}[hadoop@master elasticsearch-2.4.0]$ [hadoop@master elasticsearch-2.4.0]$?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
? 3)如果傳遞的版本號和待更新的文檔的版本號不一致,則會更新失敗。
現在,待更新文檔的版本號是3。我分別傳1和穿4進入,都會報更新失敗。如下
[hadoop@master elasticsearch-2.4.0]$ curl -XPOST http://master:9200/zhouls/user/2/_update?version=2 -d '{"doc" :{"age" : 30}}' {"_index":"zhouls","_type":"user","_id":"2","_version":3,"_shards":{"total":2,"successful":2,"failed":0}}[hadoop@master elasticsearch-2.4.0]$ [hadoop@master elasticsearch-2.4.0]$ [hadoop@master elasticsearch-2.4.0]$ curl -XPOST http://master:9200/zhouls/user/2/_update?version=1 -d '{"doc" :{"age" : 30}}' {"error":{"root_cause":[{"type":"version_conflict_engine_exception","reason":"[user][2]: version conflict, current [3], provided [1]","index":"zhouls","shard":"2"}],"type":"version_conflict_engine_exception","reason":"[user][2]: version conflict, current [3], provided [1]","index":"zhouls","shard":"2"},"status":409}[hadoop@master elasticsearch-2.4.0]$ [hadoop@master elasticsearch-2.4.0]$ [hadoop@master elasticsearch-2.4.0]$ curl -XPOST http://master:9200/zhouls/user/2/_update?version=4 -d '{"doc" :{"age" : 30}}' {"error":{"root_cause":[{"type":"version_conflict_engine_exception","reason":"[user][2]: version conflict, current [3], provided [4]","index":"zhouls","shard":"2"}],"type":"version_conflict_engine_exception","reason":"[user][2]: version conflict, current [3], provided [4]","index":"zhouls","shard":"2"},"status":409}[hadoop@master elasticsearch-2.4.0]$ [hadoop@master elasticsearch-2.4.0]$ [hadoop@master elasticsearch-2.4.0]$?
?
?
?
?
更多,請見
Elasticsearch筆記三之版本控制和插件
?
總結
以上是生活随笔為你收集整理的Elasticsearch之CURL命令的version控制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Maven环境搭建
- 下一篇: 钉钉微应用的开发——主前端