0
我想找出ElasticSearch中給定索引的別名。基本上,這個問題的反面:How to find Index by Alias in Elasticsearch java api?如何在ElasticSearch中找到索引的別名
我想找出ElasticSearch中給定索引的別名。基本上,這個問題的反面:How to find Index by Alias in Elasticsearch java api?如何在ElasticSearch中找到索引的別名
這就是我做到的。
// Get the map of [alias => [index => metadata, ...], ...]
ImmutableOpenMap<String, ImmutableOpenMap<String, AliasMetaData>> aliasesAndIndices =
client.admin().cluster()
.prepareState().execute().actionGet().getState()
.getMetaData().getAliases();
Map<String, String> aliasForIndex = new HashMap<>();
// Convert it to a map of [index => alias, ...]
for (String alias : aliasesAndIndices.keys().toArray(String.class)) {
ImmutableOpenMap<String, AliasMetaData> innerMap = aliasesAndIndices.get(alias);
for (String index : innerMap.keys().toArray(String.class)) {
aliasForIndex.put(index, alias);
}
}
然後我可以得到像這樣的索引的別名。
aliasForIndex.get(index)