我想列出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"
}
我想要一个所有索引的列表..
我用它来得到所有的指标:
$ curl --silent 'http://127.0.0.1:9200/_cat/indices' | cut -d\ -f3
有了这个列表,你就可以……
例子
$ curl -s 'http://localhost:9200/_cat/indices' | head -5
green open qa-abcdefq_1458925279526 1 6 0 0 1008b 144b
green open qa-test_learnq_1460483735129 1 6 0 0 1008b 144b
green open qa-testimportd_1458925361399 1 6 0 0 1008b 144b
green open qa-test123p_reports 1 6 3868280 25605 5.9gb 870.5mb
green open qa-dan050216p_1462220967543 1 6 0 0 1008b 144b
要获得上面的第三列(索引的名称):
$ curl -s 'http://localhost:9200/_cat/indices' | head -5 | cut -d\ -f3
qa-abcdefq_1458925279526
qa-test_learnq_1460483735129
qa-testimportd_1458925361399
qa-test123p_reports
qa-dan050216p_1462220967543
注意:你也可以使用awk '{print $3}'来代替cut -d\ -f3。
列标题
还可以使用?v作为查询的后缀,以添加列标头。这样做会打破缺口……方法,所以我建议使用awk..此时的选择。
$ curl -s 'http://localhost:9200/_cat/indices?v' | head -5
health status index pri rep docs.count docs.deleted store.size pri.store.size
green open qa-abcdefq_1458925279526 1 6 0 0 1008b 144b
green open qa-test_learnq_1460483735129 1 6 0 0 1008b 144b
green open qa-testimportd_1458925361399 1 6 0 0 1008b 144b
green open qa-test123p_reports 1 6 3868280 25605 5.9gb 870.5mb
_stats/ indexes给出带有索引的结果。
$ curl -XGET "localhost:9200/_stats/indices?pretty=true"
{
"_shards" : {
"total" : 10,
"successful" : 5,
"failed" : 0
},
"_all" : {
"primaries" : { },
"total" : { }
},
"indices" : {
"visitors" : {
"primaries" : { },
"total" : { }
}
}
}
您还可以使用获取特定的索引
curl -X GET "localhost:9200/<INDEX_NAME>"
e.g. curl -X GET "localhost:9200/twitter"
You may get output like:
{
"twitter": {
"aliases": {
},
"mappings": {
},
"settings": {
"index": {
"creation_date": "1540797250479",
"number_of_shards": "3",
"number_of_replicas": "2",
"uuid": "CHYecky8Q-ijsoJbpXP95w",
"version": {
"created": "6040299"
},
"provided_name": "twitter"
}
}
}
}
更多信息
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html