List all indexes on ElasticSearch server?
Solution 1:
For a concise list of all indices in your cluster, call
curl http://localhost:9200/_aliases
this will give you a list of indices and their aliases.
If you want it pretty-printed, add pretty=true
:
curl http://localhost:9200/_aliases?pretty=true
The result will look something like this, if your indices are called old_deuteronomy
and mungojerrie
:
{
"old_deuteronomy" : {
"aliases" : { }
},
"mungojerrie" : {
"aliases" : {
"rumpleteazer" : { },
"that_horrible_cat" : { }
}
}
}
Solution 2:
Try
curl 'localhost:9200/_cat/indices?v'
It will give you following self explanatory output in a tabular manner
health index pri rep docs.count docs.deleted store.size pri.store.size
yellow customer 5 1 0 0 495b 495b
Solution 3:
You can query localhost:9200/_status
and that will give you a list of indices and information about each. The response will look something like this:
{
"ok" : true,
"_shards" : { ... },
"indices" : {
"my_index" : { ... },
"another_index" : { ... }
}
}
Solution 4:
The _stats command provides ways to customize the results by specifying the metrics wished. To get the indices the query is as follows:
GET /_stats/indices
The general format of the _stats
query is:
/_stats
/_stats/{metric}
/_stats/{metric}/{indexMetric}
/{index}/_stats
/{index}/_stats/{metric}
Where the metrics are:
indices, docs, store, indexing, search, get, merge,
refresh, flush, warmer, filter_cache, id_cache,
percolate, segments, fielddata, completion
As an exercice to myself, I've written a small elasticsearch plugin providing the functionality to list elasticsearch indices without any other information. You can find it at the following url:
http://blog.iterativ.ch/2014/04/11/listindices-writing-your-first-elasticsearch-java-plugin/
https://github.com/iterativ/elasticsearch-listindices
Solution 5:
I use this to get all indices:
$ curl --silent 'http://127.0.0.1:9200/_cat/indices' | cut -d\ -f3
With this list you can work on...
Example
$ 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
To get the 3rd column above (names of the indices):
$ 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
NOTE: You can also use awk '{print $3}'
instead of cut -d\ -f3
.
Column Headers
You can also suffix the query with a ?v
to add a column header. Doing so will break the cut...
method so I'd recommend using the awk..
selection at this point.
$ 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