[英]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. 否则,默认情况下还将返回其他数据,例如索引的
MAPPINGS
和SETTINGS
。
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.