Search in sources :

Example 1 with GetIndexRequestBuilder

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;
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) IndexSet(org.graylog2.indexer.IndexSet) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) GetIndexRequestBuilder(org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder) NotNull(javax.validation.constraints.NotNull)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 NotNull (javax.validation.constraints.NotNull)1 GetIndexRequestBuilder (org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder)1 GetIndexResponse (org.elasticsearch.action.admin.indices.get.GetIndexResponse)1 AliasMetaData (org.elasticsearch.cluster.metadata.AliasMetaData)1 IndexSet (org.graylog2.indexer.IndexSet)1