问题 通过Java API列出所有可用索引[关闭]


如何通过Java API获取所有可用索引的列表?

使用REST,它只是以下HTTP-Request:

http://XXX.XXX.XXX.XXX:9200/_aliases

但为了保持一致性,通过Java API执行此操作会很不错。


2091
2017-08-01 10:04


起源



答案:


使用Java API和elasticsearch的等价物 org.elasticsearch.client.Client 课程是:

 client.admin().cluster()
    .prepareState().execute()
    .actionGet().getState()
    .getMetaData().aliases();

13
2017-08-01 10:18



小注意:我误用了 concreteAllIndices() 而不是你的想法 aliases() 当我接受你的anwser。 aliases() 如果我使用它,只返回一个空地图, concreteAllIndices() 而是返回一个包含所有索引的String数组。虽然你的anwser应该是正确的 当量 (不确定为什么我的应用程序中的地图为空)。 - Basti Funck
这是因为别名和索引是两个不同的概念 - Matt Broekhuis
以上答案不适用于1.4.4版本的ES版本而是使用以下内容。 ObjectLookupContainer <String> mapAl = client.admin()。cluster().prepareState()。execute()。actionGet()。getState()。getMetaData()。indices()。keys(); - Charith
client.admin()。indices()。stats(new IndicesStatsRequest())。actionGet()。getIndices()。keySet()在1.4版本中工作 - Avinash Kumar Pandey


答案:


使用Java API和elasticsearch的等价物 org.elasticsearch.client.Client 课程是:

 client.admin().cluster()
    .prepareState().execute()
    .actionGet().getState()
    .getMetaData().aliases();

13
2017-08-01 10:18



小注意:我误用了 concreteAllIndices() 而不是你的想法 aliases() 当我接受你的anwser。 aliases() 如果我使用它,只返回一个空地图, concreteAllIndices() 而是返回一个包含所有索引的String数组。虽然你的anwser应该是正确的 当量 (不确定为什么我的应用程序中的地图为空)。 - Basti Funck
这是因为别名和索引是两个不同的概念 - Matt Broekhuis
以上答案不适用于1.4.4版本的ES版本而是使用以下内容。 ObjectLookupContainer <String> mapAl = client.admin()。cluster().prepareState()。execute()。actionGet()。getState()。getMetaData()。indices()。keys(); - Charith
client.admin()。indices()。stats(new IndicesStatsRequest())。actionGet()。getIndices()。keySet()在1.4版本中工作 - Avinash Kumar Pandey