use of org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder in project graylog2-server by Graylog2.
the class Indices method getIndexNamesAndAliases.
@NotNull
public Map<String, Set<String>> getIndexNamesAndAliases(String indexPattern) {
// only request indices matching the name or pattern in `indexPattern` and only get the alias names for each index,
// not the settings or mappings
final GetIndexRequestBuilder getIndexRequestBuilder = c.admin().indices().prepareGetIndex();
getIndexRequestBuilder.addFeatures(GetIndexRequest.Feature.ALIASES);
getIndexRequestBuilder.setIndices(indexPattern);
final GetIndexResponse getIndexResponse = c.admin().indices().getIndex(getIndexRequestBuilder.request()).actionGet();
final String[] indices = getIndexResponse.indices();
final ImmutableOpenMap<String, List<AliasMetaData>> aliases = getIndexResponse.aliases();
final Map<String, Set<String>> indexAliases = Maps.newHashMap();
for (String index : indices) {
final List<AliasMetaData> aliasMetaData = aliases.get(index);
if (aliasMetaData == null) {
indexAliases.put(index, Collections.emptySet());
} else {
indexAliases.put(index, aliasMetaData.stream().map(AliasMetaData::alias).collect(toSet()));
}
}
return indexAliases;
}
Aggregations