Elasticsearch list indices sorted by name

34,985

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
Share:
34,985
10 cls
Author by

10 cls

Updated on July 14, 2020

Comments

  • 10 cls
    10 cls almost 4 years

    How can the following query's results be sorted by index name?

    curl "localhost:9200/_aliases?pretty"
    
    • progrrammer
      progrrammer almost 10 years
      Can't you sort by your own? I don't think it exists.
    • 10 cls
      10 cls almost 10 years
      @ErBnAcharya The result has no field name to specify.
    • 10 cls
      10 cls almost 10 years
      @ErBnAcharya How is that done?
    • Alcanzar
      Alcanzar almost 10 years
      have 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
      Miae Kim about 8 years
      I recommend to use sort as @Alcanzar said. Try curl localhost:9200/_cat/indices | sort -nk2
  • 10 cls
    10 cls almost 10 years
    Ah, 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
    10 cls over 9 years
    Ah, nice. I've changed it slightly to: curl --silent 'http://path.to.cluster:9200/_cat/aliases' | cut -d ' ' -f1 | sort
  • Mike Rylander
    Mike Rylander over 8 years
    I had to change the cut to use -f3 instead of -f2.
  • Miae Kim
    Miae Kim over 7 years
    You can use -n(numeric sort) option and -k(key) option for sort instead of using cut. For example, curl 'localhost:9200/_cat/indices' | sort -nk 3
  • Romain
    Romain over 6 years
    what 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
    w00ngy over 6 years
    I 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
    Miles O'Keefe about 6 years
    You can also change the sort order: /_cat/indices?v&s=docs.count:desc
  • Indrajeet Gour
    Indrajeet Gour over 5 years
    Plus +1 hands up for reverse ordering
  • akki
    akki almost 5 years
    This answer tells about so many features in a very clean fashion.
  • Rupesh
    Rupesh almost 3 years
    How to sort in descending order using the above solution ?
  • F. Pareto
    F. Pareto over 2 years
    I 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
    F. Pareto over 2 years
    @Rupesh: sort --reverse