[英]Elasticsearch Java Rest Client: how to get the list of all indices
如何使用Rest Client在Elasticsearch中獲取所有索引的列表?
(我在網上找到的所有答案似乎都與舊類型的客戶有關。
我無法在文檔中找到直接答案,
https://www.elastic.co/guide/zh-CN/elasticsearch/client/java-rest/current/index.html
無法找出要研究的部分,群集API或索引API等)
在當前的Java高級REST客戶端中,您可以簡單地通過請求帶有“ *”作為索引名稱的GetIndex請求來列出所有索引。
GetIndexRequest request = new GetIndexRequest().indices("*");
GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
String[] indices = response.getIndices();
通過REST API,您可以使用以下URL進行驗證: http:// elasticsearch:9200 / _cat / indices?v
通過Java Client API(我才意識到您是這樣問的):您可以押注Cluster Health API: https : //www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java- rest-high-cluster-health.html
並使用
ClusterHealthRequest request = new ClusterHealthRequest();
ClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT);
Set<String> indices = response.getIndices().keySet();
您將獲得索引列表;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.