Elasticsearch list indices sorted by name
Solution 1
I think that the best way to do this would be via the console. Something like this:
$ curl --silent 'http://path.to.cluster:9200/_cat/indices' | cut -d ' ' -f2 | sort
Solution 2
You can ask ES to sort the results via the s
(sort) searchParameter using s=i
or s=index
curl "localhost:9200/_cat/indices?pretty&s=i"
curl "localhost:9200/_cat/aliases?pretty&s=index"
To see the column's headers, add "&v" :
curl "localhost:9200/_cat/indices?pretty&v&s=index"`.
You can find some explanations in the cat/indices documentation
Solution 3
The best way for Elasticsearch 5x is like this:
GET _cat/aliases?v&s=index:desc&h=alias,index
Will give you:
alias index
app-logs-alias app-logs-2017-12-31
backend-logs-read backend-logs-2017-12-31
s = sort, v = various extra detail, h = headings to include,
Solution 4
This is an old question, but now in 2020 the best way is :
with kibana :
GET _cat/indices/?pretty&s=store.size:desc
with curl :
http://localhost:9200/_cat/indices/?pretty&s=store.size:desc
Desc at the end for sort by desc
Solution 5
Just use this get request it will show all indexes with the column name.
http://localhost:9200/_cat/indices/?pretty&v
Additionally, not only by name you can sort it by any parameter you want with a get parameter of s=column_name
.
for example; to sort by the size you can do like:
http://localhost:9200/_cat/indices/?pretty&s=store.size
similarly for name:
http://localhost:9200/_cat/indices/?pretty&s=index
10 cls
Updated on July 14, 2020Comments
-
10 cls almost 4 years
How can the following query's results be sorted by index name?
curl "localhost:9200/_aliases?pretty"
-
progrrammer almost 10 yearsCan't you sort by your own? I don't think it exists.
-
10 cls almost 10 years@ErBnAcharya The result has no field name to specify.
-
10 cls almost 10 years@ErBnAcharya How is that done?
-
Alcanzar almost 10 yearshave you tried
curl localhost:9200/_cat/aliases | sort
? I realize it's a completely different format, but it might be what you really wanted -
Miae Kim about 8 yearsI recommend to use
sort
as @Alcanzar said. Trycurl localhost:9200/_cat/indices | sort -nk2
-
-
10 cls almost 10 yearsAh, I'm interested to see if there's an api alternative. Along with simple re-indexing such as copy myindex testindex ( github.com/elasticsearch/elasticsearch/issues/1077 closed? ) there seem to be some unexpected omissions.
-
10 cls over 9 yearsAh, nice. I've changed it slightly to:
curl --silent 'http://path.to.cluster:9200/_cat/aliases' | cut -d ' ' -f1 | sort
-
Mike Rylander over 8 yearsI had to change the cut to use
-f3
instead of-f2
. -
Miae Kim over 7 yearsYou can use
-n(numeric sort)
option and-k(key)
option forsort
instead of usingcut
. For example,curl 'localhost:9200/_cat/indices' | sort -nk 3
-
Romain over 6 yearswhat do you mean ? curl is just doing an http request, you can use it in a browser or with any http client in any language
-
w00ngy over 6 yearsI couldn't get any of these to work via a postman get on ES 5.2+. I get 400 response "illegal_argument_exception, request [/_aliases/] contains unrecognized parameter: [s]"
-
Miles O'Keefe about 6 yearsYou can also change the sort order:
/_cat/indices?v&s=docs.count:desc
-
Indrajeet Gour over 5 yearsPlus +1 hands up for reverse ordering
-
akki almost 5 yearsThis answer tells about so many features in a very clean fashion.
-
Rupesh almost 3 yearsHow to sort in descending order using the above solution ?
-
F. Pareto over 2 yearsI had to use
awk
because the spaces delimiting each column where not constant for me:$ curl --silent 'http://path.to.cluster:9200/_cat/indices' | awk '{ print $3 }' | sort
-
F. Pareto over 2 years@Rupesh:
sort --reverse