Elasticsearch 删除type

首先要说明的是现在的Elasticsearch已经不支持删除一个type了,所以使用delete命令想要尝试删除一个type的时候会出现如下错误,如果存在一个名为edemo的index和tets的type:

No handler found for uri [/edemo/test] and method [DELETE]
  • 1

所以现在如果想要删除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": {}
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

并不需要插件,直接执行该条命令就可以进行删除了:

这里写图片描述

猜你喜欢

转载自blog.csdn.net/youzhouliu/article/details/79940729