Elasticsearch之CURL命令的version控制
?
?
普通關(guān)系型數(shù)據(jù)庫使用的是(悲觀并發(fā)控制(PCC))
當(dāng)我們?cè)谛薷囊粋€(gè)數(shù)據(jù)前先鎖定這一行,然后確保只有讀取到數(shù)據(jù)的這個(gè)線程可以修改這一行數(shù)據(jù)
ES使用的是(樂觀并發(fā)控制(OCC))
ES不會(huì)阻止某一數(shù)據(jù)的訪問,然而,如果基礎(chǔ)數(shù)據(jù)在我們讀取和寫入的間隔中發(fā)生了變化,更新就會(huì)失敗,這時(shí)候就由程序來決定如何處理這個(gè)沖突。它可以重新讀取新數(shù)據(jù)來進(jìn)行更新,又或者將這一情況直接反饋給用戶。
ES如何實(shí)現(xiàn)版本控制(使用es內(nèi)部版本號(hào))
1)首先得到想要修改的文檔,獲取版本version號(hào)
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)在執(zhí)行更新操作的時(shí)候把版本號(hào)傳過去
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)如果傳遞的版本號(hào)和待更新的文檔的版本號(hào)不一致,則會(huì)更新失敗。
現(xiàn)在,待更新文檔的版本號(hào)是3。我分別傳1和穿4進(jìn)入,都會(huì)報(bào)更新失敗。如下
[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]$?
?
?
?
?
更多,請(qǐng)見
Elasticsearch筆記三之版本控制和插件
?
總結(jié)
以上是生活随笔為你收集整理的Elasticsearch之CURL命令的version控制的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Maven环境搭建
- 下一篇: 钉钉微应用的开发——主前端