如同磁铁吸引四周的铁粉,热情也能吸引周围的人,改变周围的情况。

在es2.1版本中如何删除一个type下的数据

Elasticsearch | 作者 tompanda | 发布于2016年01月04日 | 阅读数:10976

在2.x.x版本的es中之前删除type的restful接口好像不能用了, 提供的是一个plugin, 但是文档中没有找到如何将一个完整的type全部物理删除掉得方式.
这里强调一下物理删除, 数据真的是从硬盘中删除掉.

哪位朋友可以指点一下
已邀请:

zttech

赞同来自: PJ soltex

前提:安装插件 delete by query.

DELETE /test/test/_query
{
  "query":{
    "match_all":{}
  }
}

zttech

赞同来自: tompanda

internally, es has marked the old document as deleted and added an entirely new document. the old version of the document doesn’t disappear immediately, although you wont be able to access it. es clean up deleted documents in the background as you continue to index more data。

tompanda

赞同来自:

[eagleye@10-236 elasticsearch-2.1.1]$ bin/plugin install delete-by-query
-> Installing delete-by-query...
Trying https://download.elastic.co/el ... 1.zip ...
Downloading ..DONE
Verifying https://download.elastic.co/el ... 1.zip checksums if available ...
Downloading .DONE
Installed delete-by-query into /home/eagleye/elasticsearch-2.1.1/plugins/delete-by-query
[eagleye@10-236 elasticsearch-2.1.1]$ bin/plugin install d^C
[eagleye@10-236 elasticsearch-2.1.1]$ curl -XDELETE http://192.168.10.236:9200/eag ... query -d '{"query":{"match_all":{}}}'
{"found":false,"_index":"eagleye_bigindex_2015.12.24","_type":"log","_id":"_query","_version":1,"_shards":{"total":2,"successful":2,"failed":0}}[eagleye@10-236 elasticsearch-2.1.1]$
 
您说的方式我之前就试过, 但是没有成功, 所以很困惑

yinglunfeng - 90后系统工程师

赞同来自:

如果你的日志使用logstash-%{type}这样的索引去存储那就好办了。
比如存储apache日志的索引logstash-apache-2015.12-31
你可以直接进入es的数据目录查找N天前修改的目录(目录就是索引名),然后利用curl -XDELETE ip:9200/索引名进行删除。在linux中结合计划任务的话,可以写一个类似如下的脚本定期删除:
#!/bin/bash
datadir="/home/elk/elasticsearch/data/UCWeb_foxy/nodes/0/indices"

function delete_index(){
   index_prefix=$1
   save_day=$2
   cd $datadir
   for file in `find ./ -type d -name "${index_prefix}*" -mtime +${save_day}`
   do
      curl -XDELETE $(hostname -i):9200/$(basename $file)
      #如:curl -XDELETE 127.0.0.1:9200/logstash-apache-2015-12-31
   done


#第一个参数为要删除的索引类型,第二个参数索引保存天数
delete_index logstash-u2 5
delete_index logstash-u3 5
delete_index logstash-ping 90

要回复问题请先登录注册