我想列出ElasticSearch服务器上的所有索引。我试了一下:
curl -XGET localhost:9200/
但它给了我这个:
{
"ok" : true,
"status" : 200,
"name" : "El Aguila",
"version" : {
"number" : "0.19.3",
"snapshot_build" : false
},
"tagline" : "You Know, for Search"
}
我想要一个所有索引的列表..
我使用_stats/indexes端点来获得一个json blob数据,然后用jq进行过滤。
curl 'localhost:9200/_stats/indexes' | jq '.indices | keys | .[]'
"admin"
"blazeds"
"cgi-bin"
"contacts_v1"
"flex2gateway"
"formmail"
"formmail.pl"
"gw"
...
如果你不想要引号,给jq添加一个-r标志。
是的,端点是索引,数据键是索引,所以他们也无法做出决定:)
我需要它来清理内部安全扫描(nessus)创建的这些垃圾索引。
PS:如果您打算从命令行与ES交互,我强烈建议您熟悉jq。
要获得集群中所有索引的简明列表,请调用
curl http://localhost:9200/_aliases
这将为您提供索引及其别名的列表。
如果你想要漂亮的打印,添加pretty=true:
curl http://localhost:9200/_aliases?pretty=true
如果你的索引是old_deuteronomy和mungojerrie,结果会是这样的:
{
"old_deuteronomy" : {
"aliases" : { }
},
"mungojerrie" : {
"aliases" : {
"rumpleteazer" : { },
"that_horrible_cat" : { }
}
}
}