398

I would like to list all indexes present on an ElasticSearch server. I tried this:

curl -XGET localhost:9200/

but it just gives me this:

{
  "ok" : true,
  "status" : 200,
  "name" : "El Aguila",
  "version" : {
    "number" : "0.19.3",
    "snapshot_build" : false
  },
  "tagline" : "You Know, for Search"
}

I want a list of all indexes..

0

23 Answers 23

614

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" : { }
    }
  }
}
6
  • 8
    @paweloque answer now looks like it's the correct solution; seems cleaner. curl http://localhost:9200/_stats/indexes\?pretty\=1
    – notapatch
    Mar 28, 2014 at 12:09
  • 1
    My 2 cents for a plain (non-json) list: curl -s localhost:9200/_aliases?pretty=true | awk -F\" '!/aliases/ && $2 != "" {print $2}'
    – Yaron
    Apr 21, 2015 at 15:14
  • 1
    For Elasticsearch 6.5 either hit the /stats endpoint, or the health endpoint with param _cluster/health?level=indices
    – Justin W.
    Feb 23, 2019 at 1:22
  • 1
    curl localhost:9200/_cat/indices?v worked for me (on Elastic 6.2.4)
    – Matt L.
    Aug 1, 2019 at 17:24
  • 3
    I don't know what is out of date but did exactly what I needed as of 2022 on LTS ECK. Jan 7, 2022 at 9:54
182

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
7
  • Adding a pipe to sort made this easy to see what was going green. Also the store.size changing indicated additional progress.
    – kevpie
    Sep 28, 2015 at 8:24
  • you can also select and order columns adding e.g. &h=health,index as well as sort with &s=health:desc Dec 18, 2018 at 19:33
  • Be careful when using this command, it may crash your cluster!!!
    – babis21
    Nov 27, 2020 at 10:29
  • 2
    @FlorianCastelain to be honest I cannot find the resources now. It's been some time since I tried to deal with this issue. I remember that there was a note in the docs but I cannot see it anymore (perhaps it was in some other resource). Bottom line was that the _cat API triggers some expensive operations in the cluster. We have a very busy cluster and in our case the cluster crashes when I call _cat/indices. Same happens for _cat/nodes. We just stopped using it, we have many problems with ES and we are in a process of replacing it. For the record, we face this issue with ES version 5.6.
    – babis21
    Jan 4, 2021 at 12:54
  • 1
    @Florian just came across this comment: discuss.elastic.co/t/high-cpu-usage-while-bulk-indexing/135023/… from an old thread, in case it helps
    – babis21
    Sep 21, 2021 at 15:02
39

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" : { ... }
  }
}
6
  • 3
    If you just want to know list of index names then this approach is too much and slower. Better use - GET /_stats/indexes
    – asyncwait
    Jul 12, 2014 at 6:45
  • 6
    @asyncwait I'd recommend /_stats/indices since it's the correct plural and also the key used in /_status and in /_stats. Jan 15, 2015 at 9:53
  • 8
    Doesn't seem to be a valid URL anymore on version 5.6. Nov 3, 2017 at 16:00
  • 6
    API endpoint has changed to _nodes/stats and _nodes/status @KimberlyW
    – maxymoo
    Apr 4, 2018 at 2:23
  • 1
    Deprecated in 1.2.0.
    – jarmod
    Aug 7, 2018 at 17:59
32

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

3
  • 11
    Doesn't work: "type": "illegal_argument_exception", "reason": "request [/_stats/indices] contains unrecognized metric: [indices]" Jan 16, 2018 at 9:42
  • 2
    @IvanYurchenko I've implemented my elasticsearch plugin long time ago. Very possible that the APIs have changed since and it doesn't work anymore.. Best is to use the '_aliases' command. It will also provide information about all indices in elasticsearch.
    – paweloque
    Jan 16, 2018 at 17:36
  • illegal argument exception
    – Asher
    May 31, 2022 at 16:03
30

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
2
  • 2
    curl -s 'http://localhost:9200/_cat/indices?h=index' will print out just the index name. No need to use shell tricks to filter the column.
    – hgf
    Jan 2, 2018 at 14:56
  • not only can you use awk, you should use awk (or else use tr -s ' ' before cut to condense runs of spaces) or else you won't get the index name if the status is red because it will be padded with spaces and cut treats each individual space as delimiting a new field even if that "field" ends up empty
    – kbolino
    Apr 12, 2018 at 23:19
29

The simplest way to get a list of only indexes is to use the answer above, with the 'h=index' parameter:

curl -XGET "localhost:9200/_cat/indices?h=index"
19
To get all the details in Kibana.
 GET /_cat/indices




To get names only in Kibana.
GET /_cat/indices?h=index

Without using Kibana ,You can send a get request in postman or type this in Brower so you will get a list of indices names

http://localhost:9200/_cat/indices?h=index

enter image description here enter image description here

16

I would also recommend doing /_cat/indices which gives a nice human readable list of your indexes.

0
13

curl -XGET 'http://localhost:9200/_cluster/health?level=indices'

This will output like below

{
  "cluster_name": "XXXXXX:name",
  "status": "green",
  "timed_out": false,
  "number_of_nodes": 3,
  "number_of_data_nodes": 3,
  "active_primary_shards": 199,
  "active_shards": 398,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 0,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 100,
  "indices": {
    "logstash-2017.06.19": {
      "status": "green",
      "number_of_shards": 3,
      "number_of_replicas": 1,
      "active_primary_shards": 3,
      "active_shards": 6,
      "relocating_shards": 0,
      "initializing_shards": 0,
      "unassigned_shards": 0
    },
    "logstash-2017.06.18": {
      "status": "green",
      "number_of_shards": 3,
      "number_of_replicas": 1,
      "active_primary_shards": 3,
      "active_shards": 6,
      "relocating_shards": 0,
      "initializing_shards": 0,
      "unassigned_shards": 0
    }}
2
8

send requtest and get response with kibana,kibana is can autocomplete elastic query builder and have more tools

look at the kibana

 GET /_cat/indices

kibana dev tools

http://localhost:5601/app/kibana#/dev_tools/console

7

I'll give you the query which you can run on kibana.

GET /_cat/indices?v

and the CURL version will be

CURL -XGET http://localhost:9200/_cat/indices?v
1
  • 1
    I think it is the best option for viewing elastic indexes. Thanks so much :) Sep 23, 2021 at 11:34
6

Accessing the Secured Elastic Search though Curl (Update 2020)

If the Elastic Search is secured, You can use this command to list indices

curl http://username:password@localhost:9200/_aliases?pretty=true
1
  • It works for me. consider that if your password contains symbol character. before each of them you must insert backslash ( \ ) For example if your password is 12@3 you must type 12\@3 Dec 11, 2021 at 7:51
5

For Elasticsearch 6.X, I found the following the most helpful. Each provide different data in the response.

# more verbose
curl -sS 'localhost:9200/_stats' | jq -C ".indices" | less

# less verbose, summary
curl -sS 'localhost:9200/_cluster/health?level=indices' | jq -C ".indices" | less
3

I use the _stats/indexes endpoint to get a json blob of data and then filter with jq.

curl 'localhost:9200/_stats/indexes' | jq '.indices | keys | .[]'

"admin"
"blazeds"
"cgi-bin"
"contacts_v1"
"flex2gateway"
"formmail"
"formmail.pl"
"gw"
...

If you don't want quotes, add a -r flag to jq.

Yes, the endpoint is indexes and the data key is indices, so they couldn't make up their minds either :)

I needed this to clean up these garbage indices created by an internal security scan (nessus).

PS. I highly recommend getting familiar with jq if you're going to interact with ES from the command line.

3

You can also get specific index using

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"
      }
    }
  }
}

For more info

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html

2

_stats/indices gives the result with indices.

$ curl -XGET "localhost:9200/_stats/indices?pretty=true"
{
  "_shards" : {
    "total" : 10,
    "successful" : 5,
    "failed" : 0
  },
  "_all" : {
    "primaries" : { },
    "total" : { }
  },
  "indices" : {
    "visitors" : {
      "primaries" : { },
      "total" : { }
    }
  }
}
2

People here have answered how to do it in curl and sense, some people might need to do this in java.

Here it goes

client.admin().indices().stats(new IndicesStatsRequest()).actionGet().getIndices().keySet()
2

One of the best way to list indices + to display its status together with list : is by simply executing below query.

Note: preferably use Sense to get the proper output.

curl -XGET 'http://localhost:9200/_cat/shards'

The sample output is as below. The main advantage is, it basically shows index name and the shards it saved into, index size and shards ip etc

index1     0 p STARTED     173650  457.1mb 192.168.0.1 ip-192.168.0.1 
index1     0 r UNASSIGNED                                                 
index2     1 p STARTED     173435  456.6mb 192.168.0.1 ip-192.168.0.1 
index2     1 r UNASSIGNED                                                 
...
...
...
1

here's another way just to see the indices in the db:

curl -sG somehost-dev.example.com:9200/_status --user "credentials:password" | sed 's/,/\n/g' | grep index | grep -v "size_in" | uniq


{ "index":"tmpdb"}

{ "index":"devapp"}
1
<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>2.4.0</version>
</dependency>

Java API

Settings settings = Settings.settingsBuilder().put("cluster.name", Consts.ES_CLUSTER_NAME).build();
TransportClient client = TransportClient.builder().settings(settings).build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("52.43.207.11"), 9300));
IndicesAdminClient indicesAdminClient = client.admin().indices();
GetIndexResponse getIndexResponse = indicesAdminClient.getIndex(new GetIndexRequest()).get();
for (String index : getIndexResponse.getIndices()) {
    logger.info("[index:" + index + "]");
}
1
  • You could provide some explanation for the code, and make the answer a little bit more readable... How to Answer
    – AgataB
    Sep 10, 2016 at 15:36
1

If you're working in scala, a way to do this and use Future's is to create a RequestExecutor, then use the IndicesStatsRequestBuilder and the administrative client to submit your request.

import org.elasticsearch.action.{ ActionRequestBuilder, ActionListener, ActionResponse }
import scala.concurrent.{ Future, Promise, blocking }

/** Convenice wrapper for creating RequestExecutors */
object RequestExecutor {
    def apply[T <: ActionResponse](): RequestExecutor[T] = {
        new RequestExecutor[T]
    }
}

/** Wrapper to convert an ActionResponse into a scala Future
 *
 *  @see http://chris-zen.github.io/software/2015/05/10/elasticsearch-with-scala-and-akka.html
 */
class RequestExecutor[T <: ActionResponse] extends ActionListener[T] {
    private val promise = Promise[T]()

    def onResponse(response: T) {
        promise.success(response)
    }

    def onFailure(e: Throwable) {
        promise.failure(e)
    }

    def execute[RB <: ActionRequestBuilder[_, T, _, _]](request: RB): Future[T] = {
        blocking {
            request.execute(this)
            promise.future
        }
    }
}

The executor is lifted from this blog post which is definitely a good read if you're trying to query ES programmatically and not through curl. One you have this you can create a list of all indexes pretty easily like so:

def totalCountsByIndexName(): Future[List[(String, Long)]] = {
    import scala.collection.JavaConverters._
    val statsRequestBuider = new IndicesStatsRequestBuilder(client.admin().indices())
    val futureStatResponse = RequestExecutor[IndicesStatsResponse].execute(statsRequestBuider)
    futureStatResponse.map { indicesStatsResponse =>
        indicesStatsResponse.getIndices().asScala.map {
            case (k, indexStats) => {
                val indexName = indexStats.getIndex()
                val totalCount = indexStats.getTotal().getDocs().getCount()
                    (indexName, totalCount)
                }
        }.toList
    }
}

client is an instance of Client which can be a node or a transport client, whichever suits your needs. You'll also need to have an implicit ExecutionContext in scope for this request. If you try to compile this code without it then you'll get a warning from the scala compiler on how to get that if you don't have one imported already.

I needed the document count, but if you really only need the names of the indices you can pull them from the keys of the map instead of from the IndexStats:

indicesStatsResponse.getIndices().keySet()

This question shows up when you're searching for how to do this even if you're trying to do this programmatically, so I hope this helps anyone looking to do this in scala/java. Otherwise, curl users can just do as the top answer says and use

curl http://localhost:9200/_aliases
1

I had Kibana and ES installed on a machine. But I did not know the details(at what path, or port) was the ES node on that machine.

So how can you do it from Kibana (version 5.6)?

  • Go to Dev Tools
  • See Console section, and run the following query:

GET _cat/indices

I was interested in finding the the size of a particular ES index

-1

If you have curl installed on your system, then try this simple command : curl -XGET xx.xx.xx.xx:9200/_cat/indices?v

The above-mentioned command gives you result in this format : result to fetch all indices

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.