我想列出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"
}

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


当前回答

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

其他回答

您可以查询localhost:9200/_status,这将为您提供关于每个索引和信息的列表。响应看起来像这样:

{
  "ok" : true,
  "_shards" : { ... },
  "indices" : {
    "my_index" : { ... },
    "another_index" : { ... }
  }
}

我还推荐使用/_cat/ indexes,它提供了一个人类可读的索引列表。

下面是查看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"}
<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 + "]");
}

通过Curl访问安全弹性搜索(更新2020)

如果弹性搜索是安全的,您可以使用此命令列出索引

curl http://username:password@localhost:9200/_aliases?pretty=true