擴展下,
Elasticsearch之curl刪除索引庫
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XDELETE 'http://192.168.80.200:9200/zhouls/emp/1'
{"found":true,"_index":"zhouls","_type":"emp","_id":"1","_version":5,"_shards":{"total":2,"successful":1,"failed":0}}[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XGET 'http://192.168.80.200:9200/zhouls/emp/1?pretty'
{
"_index" : "zhouls",
"_type" : "emp",
"_id" : "1",
"found" : false
}
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XDELETE 'http://192.168.80.200:9200/zhouls/emp/1'
{"found":false,"_index":"zhouls","_type":"emp","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0}}[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XDELETE 'http://192.168.80.200:9200/zhouls/emp/1'
{"found":false,"_index":"zhouls","_type":"emp","_id":"1","_version":2,"_shards":{"total":2,"successful":1,"failed":0}}[hadoop@djt002 elasticsearch-2.4.3]$
es的機制,第一次刪除之后,在60秒之后,執行刪除命令,則version變為1,又開始增加了。(作為了解,不必感到驚訝)
ES的刪除操作補充知識
如果文檔存在,es會返回200 ok的狀態碼,found屬性值為true,_version屬性的值+1。
如果文檔不存在,es會返回404 Not Found的狀態碼,found屬性值為false,但是_version屬性的值依然會+1,這個就是內部管理的一部分,它保證了我們在多個節點間的不同操作的順序都被正確標記了。
注意:刪除一個文檔也不會立即生效,它只是被標記成已刪除。Elasticsearch將會在你之后添加更多索引的時候才會在后台進行刪除內容的清理。
ES刪除總結
ES的刪除操作,也是不會立即生效,跟更新操作類似。只是會被標記為已刪除狀態,ES后期會自動刪除。
好比,你刪除的操作一步一步累積,當達到它上限時,等你刪除幾十條數據后,ES我一次性刪除,這樣可以節省磁盤IO。
這些簡單的es刪除操作,容易的就在生產環境里,手動輸入。復雜的,用java代碼去實現。