Search in sources :

Example 1 with AliasMetadata

use of org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class ShardSearchRequest method parseAliasFilter.

/**
     * Returns the filter associated with listed filtering aliases.
     * <p>
     * The list of filtering aliases should be obtained by calling MetaData.filteringAliases.
     * Returns <tt>null</tt> if no filtering is required.</p>
     */
static QueryBuilder parseAliasFilter(CheckedFunction<byte[], QueryBuilder, IOException> filterParser, IndexMetaData metaData, String... aliasNames) {
    if (aliasNames == null || aliasNames.length == 0) {
        return null;
    }
    Index index = metaData.getIndex();
    ImmutableOpenMap<String, AliasMetaData> aliases = metaData.getAliases();
    Function<AliasMetaData, QueryBuilder> parserFunction = (alias) -> {
        if (alias.filter() == null) {
            return null;
        }
        try {
            return filterParser.apply(alias.filter().uncompressed());
        } catch (IOException ex) {
            throw new AliasFilterParsingException(index, alias.getAlias(), "Invalid alias filter", ex);
        }
    };
    if (aliasNames.length == 1) {
        AliasMetaData alias = aliases.get(aliasNames[0]);
        if (alias == null) {
            // This shouldn't happen unless alias disappeared after filteringAliases was called.
            throw new InvalidAliasNameException(index, aliasNames[0], "Unknown alias name was passed to alias Filter");
        }
        return parserFunction.apply(alias);
    } else {
        // we need to bench here a bit, to see maybe it makes sense to use OrFilter
        BoolQueryBuilder combined = new BoolQueryBuilder();
        for (String aliasName : aliasNames) {
            AliasMetaData alias = aliases.get(aliasName);
            if (alias == null) {
                // This shouldn't happen unless alias disappeared after filteringAliases was called.
                throw new InvalidAliasNameException(index, aliasNames[0], "Unknown alias name was passed to alias Filter");
            }
            QueryBuilder parsedFilter = parserFunction.apply(alias);
            if (parsedFilter != null) {
                combined.should(parsedFilter);
            } else {
                // The filter might be null only if filter was removed after filteringAliases was called
                return null;
            }
        }
        return combined;
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchType(org.elasticsearch.action.search.SearchType) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) Scroll(org.elasticsearch.search.Scroll) IOException(java.io.IOException) Index(org.elasticsearch.index.Index) BytesReference(org.elasticsearch.common.bytes.BytesReference) Function(java.util.function.Function) CheckedFunction(org.elasticsearch.common.CheckedFunction) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) AliasFilterParsingException(org.elasticsearch.indices.AliasFilterParsingException) InvalidAliasNameException(org.elasticsearch.indices.InvalidAliasNameException) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) AliasFilterParsingException(org.elasticsearch.indices.AliasFilterParsingException) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Index(org.elasticsearch.index.Index) IOException(java.io.IOException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) InvalidAliasNameException(org.elasticsearch.indices.InvalidAliasNameException)

Example 2 with AliasMetadata

use of org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class GetAliasesResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeVInt(aliases.size());
    for (ObjectObjectCursor<String, List<AliasMetaData>> entry : aliases) {
        out.writeString(entry.key);
        out.writeVInt(entry.value.size());
        for (AliasMetaData aliasMetaData : entry.value) {
            aliasMetaData.writeTo(out);
        }
    }
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with AliasMetadata

use of org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class GetIndexResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeStringArray(indices);
    out.writeVInt(mappings.size());
    for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappings) {
        out.writeString(indexEntry.key);
        out.writeVInt(indexEntry.value.size());
        for (ObjectObjectCursor<String, MappingMetaData> mappingEntry : indexEntry.value) {
            out.writeString(mappingEntry.key);
            mappingEntry.value.writeTo(out);
        }
    }
    out.writeVInt(aliases.size());
    for (ObjectObjectCursor<String, List<AliasMetaData>> indexEntry : aliases) {
        out.writeString(indexEntry.key);
        out.writeVInt(indexEntry.value.size());
        for (AliasMetaData aliasEntry : indexEntry.value) {
            aliasEntry.writeTo(out);
        }
    }
    out.writeVInt(settings.size());
    for (ObjectObjectCursor<String, Settings> indexEntry : settings) {
        out.writeString(indexEntry.key);
        Settings.writeSettingsToStream(indexEntry.value, out);
    }
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Settings(org.elasticsearch.common.settings.Settings)

Example 4 with AliasMetadata

use of org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class GetIndexResponse method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    this.indices = in.readStringArray();
    int mappingsSize = in.readVInt();
    ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> mappingsMapBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < mappingsSize; i++) {
        String key = in.readString();
        int valueSize = in.readVInt();
        ImmutableOpenMap.Builder<String, MappingMetaData> mappingEntryBuilder = ImmutableOpenMap.builder();
        for (int j = 0; j < valueSize; j++) {
            mappingEntryBuilder.put(in.readString(), new MappingMetaData(in));
        }
        mappingsMapBuilder.put(key, mappingEntryBuilder.build());
    }
    mappings = mappingsMapBuilder.build();
    int aliasesSize = in.readVInt();
    ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliasesMapBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < aliasesSize; i++) {
        String key = in.readString();
        int valueSize = in.readVInt();
        List<AliasMetaData> aliasEntryBuilder = new ArrayList<>();
        for (int j = 0; j < valueSize; j++) {
            aliasEntryBuilder.add(new AliasMetaData(in));
        }
        aliasesMapBuilder.put(key, Collections.unmodifiableList(aliasEntryBuilder));
    }
    aliases = aliasesMapBuilder.build();
    int settingsSize = in.readVInt();
    ImmutableOpenMap.Builder<String, Settings> settingsMapBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < settingsSize; i++) {
        String key = in.readString();
        settingsMapBuilder.put(key, Settings.readSettingsFromStream(in));
    }
    settings = settingsMapBuilder.build();
}
Also used : ArrayList(java.util.ArrayList) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) List(java.util.List) ArrayList(java.util.ArrayList) Settings(org.elasticsearch.common.settings.Settings)

Example 5 with AliasMetadata

use of org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class RestAliasAction method buildTable.

private Table buildTable(RestRequest request, GetAliasesResponse response) {
    Table table = getTableWithHeader(request);
    for (ObjectObjectCursor<String, List<AliasMetaData>> cursor : response.getAliases()) {
        String indexName = cursor.key;
        for (AliasMetaData aliasMetaData : cursor.value) {
            table.startRow();
            table.addCell(aliasMetaData.alias());
            table.addCell(indexName);
            table.addCell(aliasMetaData.filteringRequired() ? "*" : "-");
            String indexRouting = Strings.hasLength(aliasMetaData.indexRouting()) ? aliasMetaData.indexRouting() : "-";
            table.addCell(indexRouting);
            String searchRouting = Strings.hasLength(aliasMetaData.searchRouting()) ? aliasMetaData.searchRouting() : "-";
            table.addCell(searchRouting);
            table.endRow();
        }
    }
    return table;
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) Table(org.elasticsearch.common.Table) List(java.util.List)

Aggregations

AliasMetaData (org.elasticsearch.cluster.metadata.AliasMetaData)20 List (java.util.List)13 Settings (org.elasticsearch.common.settings.Settings)10 ArrayList (java.util.ArrayList)9 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)8 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Set (java.util.Set)5 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)4 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)4 Index (org.elasticsearch.index.Index)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 GetAliasesResponse (org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse)3 AliasMetadata (org.elasticsearch.cluster.metadata.AliasMetadata)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3