简体   繁体   English

如何使用java列出elasticsearch的所有索引名称?

[英]how to list all the indices' name of elasticsearch using java?

In my elasticsearch I want to get all the indices' name of the cluster. 在我的elasticsearch中,我想获取集群的所有索引名称。 How can I do using java? 如何使用Java? I search the internet but there's no much useful information. 我在互联网上搜索,但是没有太多有用的信息。

You can definitely do it with the following simple Java code: 您绝对可以使用以下简单的Java代码来做到这一点:

List<IndexMetaData> indices = client.admin().cluster()
    .prepareState().get().getState()
    .getMetaData().getIndices();

The list you obtain contains the details on all the indices available in your ES cluster. 您获得的列表包含ES群集中​​所有可用索引的详细信息。

You can use: 您可以使用:

client.admin().indices().prepareGetIndex().setFeatures().get().getIndices();

Use setFeatures() without parameter to just get index name. 使用不带参数的setFeatures()仅获取索引名称。 Otherwise, other data, such as MAPPINGS and SETTINGS of index, will also be returned by default. 否则,默认情况下还将返回其他数据,例如索引的MAPPINGSSETTINGS

Thanks for @Val's answer. 感谢@Val的回答。 According to your method, I use it in my projects, the code is: 根据您的方法,我在项目中使用它,代码为:

ClusterStateResponse response = transportClient.admin().cluster() .prepareState() 
    .execute().actionGet(); 
String[] indices=response.getState().getMetaData().getConcreteAllIndices();

This method can put all the indices name into a String array. 此方法可以将所有索引名称放入String数组。 The method works. 该方法有效。

there's another method I think but not tried: 我认为但没有尝试过另一种方法:

ImmutableOpenMap<String, MappingMetaData> mappings = node.client().admin().cluster()
    .prepareState().execute().actionGet().getState().‌getMetaData().getIndices(). 

then, we can get the keys of mappings to get all the indices. 然后,我们可以获取映射的键以获取所有索引。 Thanks again! 再次感谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Elasticsearch Java Rest Client:如何获取所有索引的列表 - Elasticsearch Java Rest Client: how to get the list of all indices 如何使用 Jest 从 ElasticSearch 获取索引列表 - How to get a List of Indices from ElasticSearch using Jest 使用Spring-Data Elasticsearch在Elasticsearch中动态创建索引名称 - Creating Indices name Dynamically in Elasticsearch using Spring-Data Elasticsearch 如何使用 Java 在 Elasticsearch 中返回所有结果? - How to return all the results in Elasticsearch using Java? 如何使用Java 8流将列表的元素映射到它们的索引? - How to map elements of the list to their indices using Java 8 streams? 如何在Java中获取所有索引的字段映射 - How to get fieldmapping of all indices in java Elasticsearch-Java RestHighLevelClient-如何使用滚动API获取所有文档 - Elasticsearch - Java RestHighLevelClient - how to get all documents using scroll api 如何使用带有列表作为参数的java api在elasticsearch上进行搜索 - How to do search on elasticsearch using java api with a list as parameter Java POJO Setter function 正在更新列表中所有索引的值 - Java POJO Setter function is updating the value for all indices in the list 如何使用Java中的SQL查询列出MSAccess数据库文件中所有表的名称? - How to list all tables' name in MSAccess database file using sql query in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM