首先要說明的是現在的Elasticsearch已經不支持刪除一個type了,所以使用delete命令想要嘗試刪除一個type的時候會出現如下錯誤,如果存在一個名為edemo的index和tets的type:
No handler found for uri [/edemo/test] and method [DELETE]
所以現在如果想要刪除type有兩種選擇:
1.重新設置index。
2.刪除type下的所有數據。
如果是重新設置index的話,官方建議
Delete Mappingedit
It is no longer possible to delete the mapping for a type. Instead you should delete the index and recreate it with the new mappings.
如果是想要刪除type下的所有數據的話,可以使用delete by query的方法,本人在網上查到的都是安裝delete-by-query插件,弄了半天也弄不好,最后發現現在的版本根本沒有這個插件了也不需要這個插件了。
edemo下的test中有兩條數據:
想要一次性刪除test下的所有數據內容的話,可以參考官方文檔:
其中有介紹到可以使用如下命令刪除一個type下的所有數據信息:
POST edemo/test/_delete_by_query?conflicts=proceed
{
"query": { "match_all": {} } }
並不需要插件,直接執行該條命令就可以進行刪除了: