列出ElasticSearch服务器上的所有索引?

Eva*_*Eva 212 curl elasticsearch

我想列出ElasticSearch服务器上的所有索引.我试过这个:

curl -XGET localhost:9200/
Run Code Online (Sandbox Code Playgroud)

但它只是给了我这个:

{
  "ok" : true,
  "status" : 200,
  "name" : "El Aguila",
  "version" : {
    "number" : "0.19.3",
    "snapshot_build" : false
  },
  "tagline" : "You Know, for Search"
}
Run Code Online (Sandbox Code Playgroud)

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

kar*_*rmi 354

有关群集中所有索引的简明列表,请致电

curl http://localhost:9200/_aliases
Run Code Online (Sandbox Code Playgroud)

这将为您提供索引及其别名的列表.

如果你想要它打印漂亮,添加pretty=true:

curl http://localhost:9200/_aliases?pretty=true
Run Code Online (Sandbox Code Playgroud)

如果您的索引被调用old_deuteronomy,结果将如下所示mungojerrie:

{
  "old_deuteronomy" : {
    "aliases" : { }
  },
  "mungojerrie" : {
    "aliases" : {
      "rumpleteazer" : { },
      "that_horrible_cat" : { }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

  • @paweloque回答*现在*看起来像是正确的解决方案; 看起来更干净 `curl http:// localhost:9200/_stats/indexes \?pretty\= 1` (5认同)
  • 我不知道哪些内容已经过时,但截至 2022 年,我在 LTS ECK 上确实做了我需要的事情。 (3认同)

Abh*_*der 61

尝试

curl 'localhost:9200/_cat/indices?v'
Run Code Online (Sandbox Code Playgroud)

我会以表格的方式给你以下自我解释的输出

health index    pri rep docs.count docs.deleted store.size pri.store.size
yellow customer   5   1          0            0       495b           495b
Run Code Online (Sandbox Code Playgroud)

  • @FlorianCastelain 说实话我现在找不到资源。我已经有一段时间没有尝试处理这个问题了。我记得文档中有一条注释,但我再也看不到它了(也许它在其他资源中)。底线是 _cat API 会触发集群中一些昂贵的操作。我们有一个非常繁忙的集群,在我们的例子中,当我调用 _cat/indices 时,集群崩溃了。_cat/nodes 也会发生同样的情况。我们刚刚停止使用它,ES 有很多问题,我们正在更换它。根据记录,我们在 ES 5.6 版本中面临这个问题。 (2认同)

小智 31

您可以查询localhost:9200/_status,这将为您提供有关每个索引和信息的列表.响应将如下所示:

{
  "ok" : true,
  "_shards" : { ... },
  "indices" : {
    "my_index" : { ... },
    "another_index" : { ... }
  }
}
Run Code Online (Sandbox Code Playgroud)

  • API端点已更改为“_nodes/stats”和“_nodes/status”@KimberlyW (6认同)
  • @asyncwait我建议使用`/ _stats/indices`,因为它是正确的复数,也是`/ _status`和`/ _stats`中使用的键. (4认同)
  • 如果您只想知道索引名称列表,那么这种方法太多而且速度太慢.更好用--`GET/_stats/index` (3认同)
  • 在 5.6 版中似乎不再是有效的 URL。 (2认同)

paw*_*que 26

_stats命令提供了通过指定所需指标来自定义结果的方法.要获取索引,查询如下:

GET /_stats/indices
Run Code Online (Sandbox Code Playgroud)

_stats查询的一般格式是:

/_stats
/_stats/{metric}
/_stats/{metric}/{indexMetric}
/{index}/_stats
/{index}/_stats/{metric}
Run Code Online (Sandbox Code Playgroud)

指标在哪里:

indices, docs, store, indexing, search, get, merge, 
refresh, flush, warmer, filter_cache, id_cache, 
percolate, segments, fielddata, completion
Run Code Online (Sandbox Code Playgroud)

作为对我自己的一个练习,我写了一个小的elasticsearch插件,提供了列出elasticsearch索引的功能,而没有任何其他信息.您可以在以下网址找到它:

http://blog.iterativ.ch/2014/04/11/listindices-writing-your-first-elasticsearch-java-plugin/

https://github.com/iterativ/elasticsearch-listindices

  • 不起作用:`"type": "illegal_argument_exception", "reason": "request [/_stats/indices] 包含无法识别的指标:[indices]"` (5认同)
  • @IvanYurchenko 我很久以前就实现了我的 elasticsearch 插件。很可能 API 已经改变了,它不再工作了..最好是使用 '_aliases' 命令。它还将提供有关 elasticsearch 中所有索引的信息。 (2认同)

Sam*_*lva 19

To get all the details in Kibana.
 GET /_cat/indices




To get names only in Kibana.
GET /_cat/indices?h=index
Run Code Online (Sandbox Code Playgroud)

不使用 Kibana ,您可以在 postman 中发送 get 请求或在 Brower 中键入此请求,这样您将获得索引名称列表

http://localhost:9200/_cat/indices?h=index
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在此输入图像描述


the*_*own 16

我用它来获取所有索引:

$ curl --silent 'http://127.0.0.1:9200/_cat/indices' | cut -d\  -f3
Run Code Online (Sandbox Code Playgroud)

有了这个列表,你可以继续......

$ 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
Run Code Online (Sandbox Code Playgroud)

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

$ 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
Run Code Online (Sandbox Code Playgroud)

注意:您也可以使用awk '{print $3}'而不是cut -d\ -f3.

列标题

您还可以使用a ?v添加列标题来后缀查询.这样做会破坏cut...方法,因此我建议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
Run Code Online (Sandbox Code Playgroud)

  • `curl -s 'http://localhost:9200/_cat/indices?h=index'` 将仅打印出索引名称。无需使用 shell 技巧来过滤列。 (2认同)

小智 16

获取仅索引列表的最简单方法是使用上面的答案,并带有 'h=index' 参数:

curl -XGET "localhost:9200/_cat/indices?h=index"
Run Code Online (Sandbox Code Playgroud)


小智 10

我还建议做/ _cat/indices,它提供了一个很好的人类可读的索引列表.


PSh*_*tty 7

curl -XGET 'http://localhost:9200/_cluster/health?level=indices'

这将输出如下

{
  "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
    }}
Run Code Online (Sandbox Code Playgroud)


Pin*_*rma 6

我会给你一个你可以在 kibana 上运行的查询。

GET /_cat/indices?v
Run Code Online (Sandbox Code Playgroud)

并且 CURL 版本将是

CURL -XGET http://localhost:9200/_cat/indices?v
Run Code Online (Sandbox Code Playgroud)


dıl*_*ücü 6

使用 kibana 发送请求并获得响应,kibana 可以自动完成弹性查询构建器并拥有更多工具

看看 kibana

 GET /_cat/indices
Run Code Online (Sandbox Code Playgroud)

kibana 开发工具

http://localhost:5601/app/kibana#/dev_tools/console


Jus*_* W. 5

对于 Elasticsearch 6.X,我发现以下内容最有帮助。每个在响应中提供不同的数据。

# 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
Run Code Online (Sandbox Code Playgroud)


sma*_*rry 5

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

如果Elastic Search是安全的,您可以使用此命令列出索引

curl http://username:password@localhost:9200/_aliases?pretty=true
Run Code Online (Sandbox Code Playgroud)