List all indexes on ElasticSearch server?

CurlElasticsearch

Curl Problem Overview


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

Curl Solutions


Solution 1 - Curl

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

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

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

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

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

Solution 6 - Curl

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"

Solution 7 - Curl

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

Solution 8 - Curl

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

Solution 9 - Curl

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

Solution 10 - Curl

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

Solution 11 - Curl

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

Solution 12 - Curl

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

Solution 13 - Curl

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

Solution 14 - Curl

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

Solution 15 - Curl

_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" : { }
    }
  }
}

Solution 16 - Curl

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()

Solution 17 - Curl

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.

Solution 18 - Curl

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

Solution 19 - Curl

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

Solution 20 - Curl

<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 + "]");
}

Solution 21 - Curl

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

Solution 22 - Curl

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

Solution 23 - Curl

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEvaView Question on Stackoverflow
Solution 1 - CurlkarmiView Answer on Stackoverflow
Solution 2 - CurlAbhijit MazumderView Answer on Stackoverflow
Solution 3 - CurlMatthew BoynesView Answer on Stackoverflow
Solution 4 - CurlpaweloqueView Answer on Stackoverflow
Solution 5 - CurlthemisterunknownView Answer on Stackoverflow
Solution 6 - CurlJ. LewisView Answer on Stackoverflow
Solution 7 - CurlMatt WatsonView Answer on Stackoverflow
Solution 8 - CurlSameera De SilvaView Answer on Stackoverflow
Solution 9 - CurlPShettyView Answer on Stackoverflow
Solution 10 - Curldılo sürücüView Answer on Stackoverflow
Solution 11 - CurlPinkesh SharmaView Answer on Stackoverflow
Solution 12 - Curlsmack cherryView Answer on Stackoverflow
Solution 13 - CurlJustin W.View Answer on Stackoverflow
Solution 14 - CurlYagnesh bhalalaView Answer on Stackoverflow
Solution 15 - CurlprayagupaView Answer on Stackoverflow
Solution 16 - CurlAvinash Kumar PandeyView Answer on Stackoverflow
Solution 17 - CurlspazmView Answer on Stackoverflow
Solution 18 - CurlTheodoreCView Answer on Stackoverflow
Solution 19 - CurlRitesh AryalView Answer on Stackoverflow
Solution 20 - CurlStanislavKoView Answer on Stackoverflow
Solution 21 - CurlEdgeCaseBergView Answer on Stackoverflow
Solution 22 - CurlrazvangView Answer on Stackoverflow
Solution 23 - CurlRanjan SinghView Answer on Stackoverflow