我想列出ElasticSearch服务器上的所有索引。我试了一下:

curl -XGET localhost:9200/

但它给了我这个:

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

我想要一个所有索引的列表..


当前回答

我用它来得到所有的指标:

$ curl --silent 'http://127.0.0.1:9200/_cat/indices' | cut -d\  -f3

有了这个列表,你就可以……

例子

$ 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

要获得上面的第三列(索引的名称):

$ 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

注意:你也可以使用awk '{print $3}'来代替cut -d\ -f3。

列标题

还可以使用?v作为查询的后缀,以添加列标头。这样做会打破缺口……方法,所以我建议使用awk..此时的选择。

$ 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

其他回答

curl -XGET 'http://localhost:9200/_cluster/health?水平=指数'

这将输出如下所示

{
  "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
    }}
To get all the details in Kibana.
 GET /_cat/indices




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

如果不使用Kibana,你可以在postman中发送一个get请求,或者在Brower中输入这个,这样你就会得到一个索引名称列表

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

Try

curl 'localhost:9200/_cat/indices?v'

它将以表格的方式为您提供以下自我说明的输出

health index    pri rep docs.count docs.deleted store.size pri.store.size
yellow customer   5   1          0            0       495b           495b

如果你的系统上安装了curl,那么试试这个简单的命令: -XGET xx.xx.xx.xx:9200/_cat/ indexes ?v

上述命令给出的结果如下所示: 结果获取所有索引

这里的人已经回答了如何在curl和sense中做到这一点,有些人可能需要在java中这样做。

开始了

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