日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Elasticsearch之CURL命令的version控制

發布時間:2025/3/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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控制的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。