如何获取在 Kibana 中创建的索引列表?

How to get the list of indices created in Kibana?

我能够从 Elasticsearch 检索索引并在 Java 中以编程方式在 Kibana 中注册相应的索引模式。现在我想获取已在 Kibana 中创建的索引模式列表,以便我可以将其与 Elasticsearch 中的索引列表进行交叉检查,以免在 Kibana 中再次创建它们。

是否有 API 从 Kibana 获取索引模式列表?

--

API 用于从 Elasticsearch 获取索引列表: http://{hostname}:{port}/_aliases

API 用于在 Kibana 中创建索引模式: http://{hostname}:{port}/{kibana instance Id}/index-pattern/{index pattern title}

恐怕目前它仍然不可用,您可以在其中使用 api 公开在 Kibana 中创建的所有索引。

但请记住,您将能够在 Kibana 中创建索引,前提是您已经在 ES 中创建了索引。因此,如果没有创建索引,也许您可​​以考虑检查您的 ES 索引是否已经有了现有索引。您可以在哪里确定,如果索引不存在于您的索引列表中,这意味着您无法继续并在 Kibana 中创建索引。

您可以从 API:

中列出它们

GET _cat/indices/.marvel* GET _cat/indices/.kibana

使用下一个查询: 获取/.kibana/index-pattern/_search

我查看了 Kibana(5.5 版)控制台,通过执行此查询可以获得相同结果

curl -X POST -H 'Content-Type: application/json' \
 -d '{"query":{"match_all":{}},"size":10000}'  \
 http://$ES_HOST/.kibana/index-pattern/_search/\?stored_fields\=""

请注意,向上面的 url 发出如下 GET 请求也会 return 字段,但限制为 10 个。

curl http://$ES_HOST/.kibana/index-pattern/_search/\?stored_fields\=""

此查询有效(来自 kibana 开发控制台):

GET .kibana/_search?size=10000
{
  "_source": ["index-pattern.title"],
  "query": {
    "term": {
      "type": "index-pattern"
    }
  }
}

适用于 kibana 7.x:

  • 获取所有索引模式
curl -s 'http://192.168.100.100:5601/api/saved_objects/_find?fields=title&fields=type&per_page=10000&type=index-pattern'

# Use jq to get the index-pattern name:
curl -s 'http://192.168.100.100:5601/api/saved_objects/_find?fields=title&fields=type&per_page=10000&type=index-pattern' | jq '.saved_objects[].attributes.title'

"guest-service*"
"activity2020*"
"bank-cockpit*"
"cros-n-wa*"
"anti-fraud20*"
"yhb-node*"
"public-service-node*"
  • 删除特定索引模式
curl -XDELETE -H 'kbn-xsrf: ""' 'http://192.168.100.100:5601/api/saved_objects/index-pattern/970070d0-f252-11ea-b492-31ec85db4535'

-H 'kbn-xsrf: ""' 必须设置否则 API 会抱怨 {"statusCode":400,"error":"Bad Request","message":"Request must contain a kbn-xsrf header."}

使用jq -r获取不带引号的值。