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)
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)
小智 31
您可以查询localhost:9200/_status,这将为您提供有关每个索引和信息的列表.响应将如下所示:
{
"ok" : true,
"_shards" : { ... },
"indices" : {
"my_index" : { ... },
"another_index" : { ... }
}
}
Run Code Online (Sandbox Code Playgroud)
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
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)
小智 16
获取仅索引列表的最简单方法是使用上面的答案,并带有 'h=index' 参数:
curl -XGET "localhost:9200/_cat/indices?h=index"
Run Code Online (Sandbox Code Playgroud)
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)
我会给你一个你可以在 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)
使用 kibana 发送请求并获得响应,kibana 可以自动完成弹性查询构建器并拥有更多工具
GET /_cat/indices
Run Code Online (Sandbox Code Playgroud)
kibana 开发工具
http://localhost:5601/app/kibana#/dev_tools/console
对于 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)
通过 Curl 访问安全的弹性搜索(2020 年更新)
如果Elastic Search是安全的,您可以使用此命令列出索引
curl http://username:password@localhost:9200/_aliases?pretty=true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
188803 次 |
| 最近记录: |