1. 程式人生 > 實用技巧 >ES命令列操作

ES命令列操作

一、索引相關

1.1 刪除索引

1.1.1 刪除指定索引
$ curl -XDELETE http://localhost:9200/索引名稱
{"acknowledged":true}
1.1.2 刪除多個索引,中間用逗號隔開
$ curl -XDELETE http://localhost:9200/索引名稱1,索引名稱2
1.1.3 模糊匹配刪除
$ curl -XDELETE -u elastic:changeme http://localhost:9200/索引名字首*
1.1.4 使用萬用字元,刪除所有索引
$ curl -XDELETE http://localhost:9200/_all
$ curl -XDELETE http://localhost:9200/*
# 二選一都可以

_all ,* 通配所有的索引,通常不建議使用萬用字元,誤刪了後果就很嚴重了,所有的index都被刪除了,禁止萬用字元為了安全起見,可以在elasticsearch.yml配置檔案中設定禁用_all和萬用字元action.destructive_requires_name = true這樣就不能使用_all和了!

1.1.5 獲取當前es索引
$ curl 'http://192.168.99.237:32706/_cat/indices?v'
1.1.6 定時刪除ES索引
30 2 * * * /usr/bin/curl -XDELETE http://localhost:9200/*-$(date -d '-3days' +'%Y.%m.%d') >/dev/null 2>&1

定時刪除指令碼:

#!/bin/bash
time=$(date -d '-3days' +'%Y.%m.%d')
curl -XDELETE -u elastic:changeme http://localhost:9200/*-${time}