Curl 列出ElasticSearch服务器上的所有索引?
我想列出ElasticSearch服务器上存在的所有索引。我试过这个:Curl 列出ElasticSearch服务器上的所有索引?,curl,elasticsearch,Curl,elasticsearch,我想列出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 -XGET localhost:9200/
但它只给了我这个:
{
"ok" : true,
"status" : 200,
"name" : "El Aguila",
"version" : {
"number" : "0.19.3",
"snapshot_build" : false
},
"tagline" : "You Know, for Search"
}
我想要一个所有索引的列表。您可以查询
localhost:9200/_status
,这将为您提供一个索引列表和关于每个索引的信息。响应将如下所示:
{
"ok" : true,
"_shards" : { ... },
"indices" : {
"my_index" : { ... },
"another_index" : { ... }
}
}
要获得集群中所有索引的简明列表,请调用
curl http://localhost:9200/_aliases
这将为您提供索引及其别名的列表
如果您希望它打印得漂亮,请添加pretty=true
:
curl http://localhost:9200/_aliases?pretty=true
如果您的索引被称为old_deuteronomy
和mungojerrie
,则结果将如下所示:
{
"old_deuteronomy" : {
"aliases" : { }
},
"mungojerrie" : {
"aliases" : {
"rumpleteazer" : { },
"that_horrible_cat" : { }
}
}
}
_stats命令提供了通过指定所需的度量来定制结果的方法。要获取索引,查询如下所示:
GET /_stats/indices
\u stats
查询的一般格式为:
/_stats
/_stats/{metric}
/_stats/{metric}/{indexMetric}
/{index}/_stats
/{index}/_stats/{metric}
其中,指标是:
indices, docs, store, indexing, search, get, merge,
refresh, flush, warmer, filter_cache, id_cache,
percolate, segments, fielddata, completion
作为我自己的练习,我编写了一个小的elasticsearch插件,提供了列出elasticsearch索引的功能,而不需要任何其他信息。您可以在以下url找到它:
这里有另一种方法可以查看数据库中的索引:
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"}
我还建议您使用/u cat/index,它提供了一个很好的人类可读的索引列表。我使用它来获取所有索引:
$ curl --silent 'http://127.0.0.1:9200/_cat/indices' | cut -d\ -f3
使用此列表,您可以处理
例子
要获取上面的第3列(索引名称):
注意:您也可以使用awk'{print$3}'
而不是cut-d \-f3
列首
您还可以在查询后加上?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
\u stats/index
使用index
给出结果
$ curl -XGET "localhost:9200/_stats/indices?pretty=true"
{
"_shards" : {
"total" : 10,
"successful" : 5,
"failed" : 0
},
"_all" : {
"primaries" : { },
"total" : { }
},
"indices" : {
"visitors" : {
"primaries" : { },
"total" : { }
}
}
}
试一试
它将以表格的方式为您提供以下自解释的输出
health index pri rep docs.count docs.deleted store.size pri.store.size
yellow customer 5 1 0 0 495b 495b
这里的人已经回答了如何在curl和sense中实现这一点,有些人可能需要在java中实现这一点 来了
client.admin().indices().stats(new IndicesStatsRequest()).actionGet().getIndices().keySet()
列出索引并与列表一起显示其状态的最佳方法之一:只需执行下面的查询 注:最好使用Sense获得正确的输出 示例输出如下所示。主要的优点是,它基本上显示了索引名和它保存到的碎片、索引大小和碎片ip等
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
...
...
...
我使用
\u stats/index
端点获取一个json数据块,然后使用进行过滤
如果不需要引号,请在jq中添加一个-r
标志
是的,端点是索引
,数据键是索引
,因此他们也无法做出决定:)
我需要它来清理内部安全扫描(nessus)创建的垃圾索引
另外,我强烈建议您熟悉是否要从命令行与ES交互。如果您在scala中工作,一种方法是创建一个RequestExecutor,然后使用和管理客户端提交您的请求
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.4.0</version>
</dependency>
import org.elasticsearch.action.{ ActionRequestBuilder, ActionListener, ActionResponse }
import scala.concurrent.{ Future, Promise, blocking }
/** Convenice wrapper for creating RequestExecutors */
object RequestExecutor {
def apply[T <: ActionResponse](): RequestExecutor[T] = {
new RequestExecutor[T]
}
}
/** Wrapper to convert an ActionResponse into a scala Future
*
* @see http://chris-zen.github.io/software/2015/05/10/elasticsearch-with-scala-and-akka.html
*/
class RequestExecutor[T <: ActionResponse] extends ActionListener[T] {
private val promise = Promise[T]()
def onResponse(response: T) {
promise.success(response)
}
def onFailure(e: Throwable) {
promise.failure(e)
}
def execute[RB <: ActionRequestBuilder[_, T, _, _]](request: RB): Future[T] = {
blocking {
request.execute(this)
promise.future
}
}
}
client
是一个实例,它可以是节点或传输客户端,以适合您的需要为准。您还需要在此请求的作用域中有一个隐式的ExecutionContext
。如果您试图在没有它的情况下编译这段代码,那么您将从scala编译器中得到一条警告,说明如果您还没有导入一段代码,如何获得该代码
我需要文档计数,但如果您确实只需要索引的名称,则可以从映射的键中而不是从索引状态中提取它们:
indicesStatsResponse.getIndices().keySet()
当您在搜索如何执行此操作时,即使您试图以编程方式执行此操作,也会出现这个问题,因此我希望这能帮助任何希望在scala/java中执行此操作的人。否则,curl用户只需按照上面的答案执行并使用
curl http://localhost:9200/_aliases
我将向您提供可以在kibana上运行的查询
GET /_cat/indices?v
卷曲版本将是
CURL -XGET http://localhost:9200/_cat/indices?v
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
}}
您还可以使用
curl -X GET "localhost:9200/<INDEX_NAME>"
e.g. curl -X GET "localhost:9200/twitter"
You may get output like:
{
"twitter": {
"aliases": {
},
"mappings": {
},
"settings": {
"index": {
"creation_date": "1540797250479",
"number_of_shards": "3",
"number_of_replicas": "2",
"uuid": "CHYecky8Q-ijsoJbpXP95w",
"version": {
"created": "6040299"
},
"provided_name": "twitter"
}
}
}
}
curl-xget“localhost:9200/”
e、 g.curl-X获取“localhost:9200/twitter”
您可能会得到如下输出:
{
“推特”:{
“别名”:{
},
“映射”:{
},
“设置”:{
“索引”:{
“创建日期”:“1540797250479”,
“碎片的数量”:“3”,
“复制副本的数量”:“2”,
“uuid”:“CHYecky8Q-ijsoJbpXP95w”,
“版本”:{
“已创建”:“6040299”
},
“提供的名称”:“推特”
}
}
}
}
更多信息
我在机器上安装了Kibana和ES。但我不知道那台机器上的ES节点的详细信息(路径或端口)
那么,如何从Kibana(5.6版)实现这一点呢
- 转到开发工具
- 请参阅控制台部分,并运行以下查询:
GET\u cat/index
我对查找特定ES索引的大小感兴趣获取索引列表的最简单方法是使用上面的答案,并使用“h=index”参数:
curl -XGET "localhost:9200/_cat/indices?h=index"
对于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
通过Curl访问安全弹性搜索(更新2020)
如果弹性搜索
是安全的,您可以使用此命令列出索引
curl http://username:password@localhost:9200/_aliases?pretty=true
如果系统上安装了curl,请尝试以下简单命令:
curl-XGET xx.xx.xx.xx:9200/_cat/index?v
上述命令以以下格式给出结果:
使用kibana发送请求并获得响应,kibana可以自动完成弹性查询生成器,并拥有更多工具
kibana开发工具
http://localhost:5601/app/kibana#/dev_tools/console
To get all the details in Kibana.
GET /_cat/indices
To get names only in Kibana.
GET /_cat/indices?h=index
不使用Kibana,您可以
CURL -XGET http://localhost:9200/_cat/indices?v
{
"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
}}
curl -X GET "localhost:9200/<INDEX_NAME>"
e.g. curl -X GET "localhost:9200/twitter"
You may get output like:
{
"twitter": {
"aliases": {
},
"mappings": {
},
"settings": {
"index": {
"creation_date": "1540797250479",
"number_of_shards": "3",
"number_of_replicas": "2",
"uuid": "CHYecky8Q-ijsoJbpXP95w",
"version": {
"created": "6040299"
},
"provided_name": "twitter"
}
}
}
}
curl -XGET "localhost:9200/_cat/indices?h=index"
# 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
curl http://username:password@localhost:9200/_aliases?pretty=true
GET /_cat/indices
To get all the details in Kibana.
GET /_cat/indices
To get names only in Kibana.
GET /_cat/indices?h=index
http://localhost:9200/_cat/indices?h=index