List all indexes on ElasticSearch server?
Asked Answered
N

24

405

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..

Nostril answered 2/7, 2013 at 13:9 Comment(0)
S
627

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" : { }
    }
  }
}
Silva answered 2/7, 2013 at 15:20 Comment(6)
@paweloque answer now looks like it's the correct solution; seems cleaner. curl http://localhost:9200/_stats/indexes\?pretty\=1Deputation
My 2 cents for a plain (non-json) list: curl -s localhost:9200/_aliases?pretty=true | awk -F\" '!/aliases/ && $2 != "" {print $2}'Bethina
For Elasticsearch 6.5 either hit the /stats endpoint, or the health endpoint with param _cluster/health?level=indicesIrizarry
curl localhost:9200/_cat/indices?v worked for me (on Elastic 6.2.4)Corwin
this answer is way out of date and should be updatedAweinspiring
I don't know what is out of date but did exactly what I needed as of 2022 on LTS ECK.Barsky
P
186

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
Pair answered 13/5, 2015 at 19:59 Comment(7)
Adding a pipe to sort made this easy to see what was going green. Also the store.size changing indicated additional progress.Overcritical
you can also select and order columns adding e.g. &h=health,index as well as sort with &s=health:descBowfin
Be careful when using this command, it may crash your cluster!!!Watt
@Watt care to explain ?Sallie
@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.Watt
@Florian just came across this comment: discuss.elastic.co/t/high-cpu-usage-while-bulk-indexing/135023/… from an old thread, in case it helpsWatt
This is the current correct answer. If you are using the curl command above exactly, remember that curl defaults to http. Depending on your configuration you may have to use curl 'https://localhost:9200/_cat/indices?v'Bora
H
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" : { ... }
  }
}
Homogenize answered 2/7, 2013 at 14:7 Comment(6)
If you just want to know list of index names then this approach is too much and slower. Better use - GET /_stats/indexesRefund
@Refund I'd recommend /_stats/indices since it's the correct plural and also the key used in /_status and in /_stats.Volution
Doesn't seem to be a valid URL anymore on version 5.6.Espadrille
API endpoint has changed to _nodes/stats and _nodes/status @KimberlyWBecky
Deprecated in 1.2.0.Bari
"invalid_index_name_exception" in v. 7Cupola
P
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

Postlude answered 2/3, 2014 at 0:21 Comment(3)
Doesn't work: "type": "illegal_argument_exception", "reason": "request [/_stats/indices] contains unrecognized metric: [indices]"Rotz
@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.Postlude
illegal argument exceptionBecome
C
31

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
Criss answered 14/8, 2014 at 10:26 Comment(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.Gabbard
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 emptyBrimful
F
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"
Feliks answered 30/11, 2018 at 13:59 Comment(0)
W
20
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

Werra answered 13/11, 2020 at 5:34 Comment(0)
T
18

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

Trimmer answered 7/8, 2014 at 18:53 Comment(0)
C
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
    }}
Coda answered 2/8, 2017 at 15:1 Comment(2)
All the other endpoints did not work for me. Your answer worked! Thx. See #49205026Doty
Me too, is this a newer version thing. The main answers seem to work on 2.x but not 6.xAggravation
L
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

Loopy answered 6/8, 2020 at 3:45 Comment(0)
F
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
Flavor answered 10/7, 2017 at 5:3 Comment(1)
I think it is the best option for viewing elastic indexes. Thanks so much :)Pratte
D
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
Dissimilar answered 6/2, 2020 at 6:58 Comment(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\@3Siamang
I
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
Irizarry answered 23/2, 2019 at 1:26 Comment(0)
B
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.

Brandebrandea answered 15/6, 2016 at 17:55 Comment(0)
K
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

Kelbee answered 29/10, 2018 at 7:25 Comment(0)
H
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" : { }
    }
  }
}
Harpsichord answered 9/1, 2015 at 8:25 Comment(0)
B
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()
Brooklyn answered 28/8, 2015 at 8:21 Comment(0)
F
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                                                 
...
...
...
Fling answered 1/6, 2016 at 16:33 Comment(0)
C
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"}
Compositor answered 20/5, 2014 at 18:3 Comment(0)
G
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 + "]");
}
Greensickness answered 10/9, 2016 at 15:14 Comment(1)
You could provide some explanation for the code, and make the answer a little bit more readable... How to AnswerPetry
P
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
Primary answered 15/11, 2016 at 14:12 Comment(0)
D
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

Disciplinant answered 7/11, 2018 at 12:57 Comment(0)
C
0

You can query with Kibana:

GET _cat/indices?v&s=store.size:asc&h=h,s,i,id,p,r,dc,dd,ss,creation.date.string

To execute from the terminal:

curl localhost:9200/_cat/indices?v&s=store.size:asc&h=h,s,i,id,p,r,dc,dd,ss,creation.date.string

s= indicates sorting.

h= specifies the columns to be displayed.

Sample Output:

h     s    i                               id                     p r    dc    dd      ss creation.date.string
green open test                            CuIbbN9LSVKGJ2Eu1WkVaA 1 0 28119 28590  66.1mb 2024-03-05T06:18:48.006Z
green open .kibana_task_manager_7.14.0_001 VsooXAwwRRy31gVUV8SHGg 1 0    14 14259  34.4mb 2024-02-27T21:03:04.483Z
green open .geoip_databases                WV4Xqzw2R6-qa9V4gbyXtQ 1 0    36    30  34.1mb 2024-02-27T21:00:14.433Z
Crosswise answered 20/3 at 8:28 Comment(0)
N
-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

Naivete answered 2/6, 2020 at 5:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.