Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何列出所有索引';使用java的elasticsearch的名称?_Java_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Java,elasticsearch" /> elasticsearch,Java,elasticsearch" />

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

如何列出所有索引';使用java的elasticsearch的名称?,java,elasticsearch,Java,elasticsearch,在elasticsearch中,我希望获得集群的所有索引名称。如何使用java? 我在网上搜索,但没有多少有用的信息 您完全可以通过以下简单的Java代码来实现: List<IndexMetaData> indices = client.admin().cluster() .prepareState().get().getState() .getMetaData().getIndices(); List index=client.admin().cluster()

在elasticsearch中,我希望获得集群的所有索引名称。如何使用java?
我在网上搜索,但没有多少有用的信息

您完全可以通过以下简单的Java代码来实现:

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

您获得的列表包含ES集群中所有可用索引的详细信息。

感谢@Val的回答。根据您的方法,我在我的项目中使用它,代码是:

ClusterStateResponse response = transportClient.admin().cluster() .prepareState() 
    .execute().actionGet(); 
String[] indices=response.getState().getMetaData().getConcreteAllIndices();
此方法可以将所有索引名称放入字符串数组中。这种方法有效

我认为还有一种方法没有尝试过:

ImmutableOpenMap<String, MappingMetaData> mappings = node.client().admin().cluster()
    .prepareState().execute().actionGet().getState().‌getMetaData().getIndices(). 
ImmutableOpenMappings=node.client().admin().cluster()
.prepareState().execute().actionGet().getState()。‌getMetaData().GetIndexs()。
然后,我们可以得到映射的键来得到所有的索引。 再次感谢

您可以使用:

client.admin()


使用不带参数的
setFeatures()
仅获取索引名。否则,其他数据,如索引的
映射
设置
,也将默认返回。

谢谢您的帮助。你的回答是一个很大的帮助。非常感谢你。我用过你的方法,效果很好。在实际项目中,代码可能会有点不同。