List all indexes on ElasticSearch server?

前端 未结 23 1089
被撕碎了的回忆
被撕碎了的回忆 2020-12-12 09:55

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:

相关标签:
23条回答
  • 2020-12-12 10:21

    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
    
    0 讨论(0)
  • 2020-12-12 10:21

    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                                                 
    ...
    ...
    ...
    
    0 讨论(0)
  • 2020-12-12 10:21

    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 讨论(0)
  • 2020-12-12 10:22

    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()
    
    0 讨论(0)
  • 2020-12-12 10:22

    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.

    0 讨论(0)
  • 2020-12-12 10:23

    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" : { }
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题