Search in sources :

Example 1 with AliasFilter

use of org.elasticsearch.search.internal.AliasFilter in project elasticsearch by elastic.

the class ShardValidateQueryRequestTests method testSerialize50Request.

// BWC test for changes from #20916
public void testSerialize50Request() throws IOException {
    ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");
    validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
    validateQueryRequest.rewrite(true);
    validateQueryRequest.explain(false);
    validateQueryRequest.types("type1", "type2");
    ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1), new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] { "alias0", "alias1" }), validateQueryRequest);
    BytesArray requestBytes = new BytesArray(Base64.getDecoder().decode("AAVpbmRleAZmb29iYXIBAQdpbmRpY2VzBAR0ZXJtP4AAAAAFZmllbGQVBXZhbHVlAgV0eXBlMQV0eXBlMgIGYWxpYXMwBmFsaWFzMQABAA"));
    try (StreamInput in = new NamedWriteableAwareStreamInput(requestBytes.streamInput(), namedWriteableRegistry)) {
        in.setVersion(Version.V_5_0_0);
        ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest();
        readRequest.readFrom(in);
        assertEquals(0, in.available());
        assertArrayEquals(request.filteringAliases().getAliases(), readRequest.filteringAliases().getAliases());
        expectThrows(IllegalStateException.class, () -> readRequest.filteringAliases().getQueryBuilder());
        assertArrayEquals(request.types(), readRequest.types());
        assertEquals(request.explain(), readRequest.explain());
        assertEquals(request.query(), readRequest.query());
        assertEquals(request.rewrite(), readRequest.rewrite());
        assertEquals(request.shardId(), readRequest.shardId());
        BytesStreamOutput output = new BytesStreamOutput();
        output.setVersion(Version.V_5_0_0);
        readRequest.writeTo(output);
        assertEquals(output.bytes().toBytesRef(), requestBytes.toBytesRef());
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ShardValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest) AliasFilter(org.elasticsearch.search.internal.AliasFilter) BytesArray(org.elasticsearch.common.bytes.BytesArray) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) ValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest) ShardValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 2 with AliasFilter

use of org.elasticsearch.search.internal.AliasFilter in project elasticsearch by elastic.

the class ClusterSearchShardsResponse method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.startObject("nodes");
    for (DiscoveryNode node : nodes) {
        node.toXContent(builder, params);
    }
    builder.endObject();
    if (indicesAndFilters != null) {
        builder.startObject("indices");
        for (Map.Entry<String, AliasFilter> entry : indicesAndFilters.entrySet()) {
            String index = entry.getKey();
            builder.startObject(index);
            AliasFilter aliasFilter = entry.getValue();
            if (aliasFilter.getAliases().length > 0) {
                builder.array("aliases", aliasFilter.getAliases());
                builder.field("filter");
                aliasFilter.getQueryBuilder().toXContent(builder, params);
            }
            builder.endObject();
        }
        builder.endObject();
    }
    builder.startArray("shards");
    for (ClusterSearchShardsGroup group : groups) {
        group.toXContent(builder, params);
    }
    builder.endArray();
    builder.endObject();
    return builder;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) AliasFilter(org.elasticsearch.search.internal.AliasFilter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with AliasFilter

use of org.elasticsearch.search.internal.AliasFilter in project elasticsearch by elastic.

the class TransportExplainAction method resolveRequest.

@Override
protected void resolveRequest(ClusterState state, InternalRequest request) {
    final AliasFilter aliasFilter = searchService.buildAliasFilter(state, request.concreteIndex(), request.request().index());
    request.request().filteringAlias(aliasFilter);
    // Fail fast on the node that received the request.
    if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) {
        throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id());
    }
}
Also used : AliasFilter(org.elasticsearch.search.internal.AliasFilter) RoutingMissingException(org.elasticsearch.action.RoutingMissingException)

Example 4 with AliasFilter

use of org.elasticsearch.search.internal.AliasFilter in project elasticsearch by elastic.

the class IndicesService method buildAliasFilter.

public AliasFilter buildAliasFilter(ClusterState state, String index, String... expressions) {
    /* Being static, parseAliasFilter doesn't have access to whatever guts it needs to parse a query. Instead of passing in a bunch
         * of dependencies we pass in a function that can perform the parsing. */
    CheckedFunction<byte[], QueryBuilder, IOException> filterParser = bytes -> {
        try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry, bytes)) {
            return new QueryParseContext(parser).parseInnerQueryBuilder();
        }
    };
    String[] aliases = indexNameExpressionResolver.filteringAliases(state, index, expressions);
    IndexMetaData indexMetaData = state.metaData().index(index);
    return new AliasFilter(ShardSearchRequest.parseAliasFilter(filterParser, indexMetaData, aliases), aliases);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) Nullable(org.elasticsearch.common.Nullable) BigArrays(org.elasticsearch.common.util.BigArrays) FlushStats(org.elasticsearch.index.flush.FlushStats) RecoveryStats(org.elasticsearch.index.recovery.RecoveryStats) ClusterState(org.elasticsearch.cluster.ClusterState) QueryPhase(org.elasticsearch.search.query.QueryPhase) IndexingStats(org.elasticsearch.index.shard.IndexingStats) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) EnumSet(java.util.EnumSet) MergeStats(org.elasticsearch.index.merge.MergeStats) SearchType(org.elasticsearch.action.search.SearchType) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) Set(java.util.Set) CollectionUtils.arrayAsArrayList(org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList) Executors(java.util.concurrent.Executors) RecoverySource(org.elasticsearch.cluster.routing.RecoverySource) CheckedFunction(org.elasticsearch.common.CheckedFunction) AliasFilter(org.elasticsearch.search.internal.AliasFilter) CountDownLatch(java.util.concurrent.CountDownLatch) Logger(org.apache.logging.log4j.Logger) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Callback(org.elasticsearch.common.util.Callback) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) ClusterService(org.elasticsearch.cluster.service.ClusterService) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) IndexModule(org.elasticsearch.index.IndexModule) Supplier(java.util.function.Supplier) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) ArrayList(java.util.ArrayList) BytesArray(org.elasticsearch.common.bytes.BytesArray) ShardRequestCache(org.elasticsearch.index.cache.request.ShardRequestCache) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) MetaDataStateFormat(org.elasticsearch.gateway.MetaDataStateFormat) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) FileSystemUtils(org.elasticsearch.common.io.FileSystemUtils) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) Files(java.nio.file.Files) Client(org.elasticsearch.client.Client) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) ShardLock(org.elasticsearch.env.ShardLock) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) CollectionUtil(org.apache.lucene.util.CollectionUtil) XContentParser(org.elasticsearch.common.xcontent.XContentParser) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) SearchStats(org.elasticsearch.index.search.stats.SearchStats) ScriptService(org.elasticsearch.script.ScriptService) ElasticsearchException(org.elasticsearch.ElasticsearchException) Property(org.elasticsearch.common.settings.Setting.Property) MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) Settings(org.elasticsearch.common.settings.Settings) ShardSearchRequest(org.elasticsearch.search.internal.ShardSearchRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) ThreadPool(org.elasticsearch.threadpool.ThreadPool) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Releasable(org.elasticsearch.common.lease.Releasable) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) PluginsService(org.elasticsearch.plugins.PluginsService) Setting(org.elasticsearch.common.settings.Setting) Collections.emptyList(java.util.Collections.emptyList) DirectoryReader(org.apache.lucene.index.DirectoryReader) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Flag(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag) BytesReference(org.elasticsearch.common.bytes.BytesReference) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) Collectors(java.util.stream.Collectors) MapBuilder.newMapBuilder(org.elasticsearch.common.collect.MapBuilder.newMapBuilder) QueryParseContext(org.elasticsearch.index.query.QueryParseContext) Engine(org.elasticsearch.index.engine.Engine) RamUsageEstimator(org.apache.lucene.util.RamUsageEstimator) MapperService(org.elasticsearch.index.mapper.MapperService) RefreshStats(org.elasticsearch.index.refresh.RefreshStats) List(java.util.List) QuerySearchResult(org.elasticsearch.search.query.QuerySearchResult) IndicesClusterStateService(org.elasticsearch.indices.cluster.IndicesClusterStateService) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) GetStats(org.elasticsearch.index.get.GetStats) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) FieldStats(org.elasticsearch.action.fieldstats.FieldStats) IndexingOperationListener(org.elasticsearch.index.shard.IndexingOperationListener) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) XContentType(org.elasticsearch.common.xcontent.XContentType) SearchContext(org.elasticsearch.search.internal.SearchContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) MetaStateService(org.elasticsearch.gateway.MetaStateService) Index(org.elasticsearch.index.Index) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) TimeValue(org.elasticsearch.common.unit.TimeValue) Iterables(org.elasticsearch.common.util.iterable.Iterables) IndexSettings(org.elasticsearch.index.IndexSettings) ExecutorService(java.util.concurrent.ExecutorService) Collections.emptyMap(java.util.Collections.emptyMap) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) IndexShardState(org.elasticsearch.index.shard.IndexShardState) IndexFieldDataCache(org.elasticsearch.index.fielddata.IndexFieldDataCache) Iterator(java.util.Iterator) AbstractLifecycleComponent(org.elasticsearch.common.component.AbstractLifecycleComponent) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Closeable(java.io.Closeable) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) AliasFilter(org.elasticsearch.search.internal.AliasFilter) QueryParseContext(org.elasticsearch.index.query.QueryParseContext) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) IOException(java.io.IOException) XContentParser(org.elasticsearch.common.xcontent.XContentParser) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 5 with AliasFilter

use of org.elasticsearch.search.internal.AliasFilter in project elasticsearch by elastic.

the class ExplainRequestTests method testSerialize50Request.

// BWC test for changes from #20916
public void testSerialize50Request() throws IOException {
    ExplainRequest request = new ExplainRequest("index", "type", "id");
    request.fetchSourceContext(new FetchSourceContext(true, new String[] { "field1.*" }, new String[] { "field2.*" }));
    request.filteringAlias(new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] { "alias0", "alias1" }));
    request.preference("the_preference");
    request.query(QueryBuilders.termQuery("field", "value"));
    request.storedFields(new String[] { "field1", "field2" });
    request.routing("some_routing");
    BytesArray requestBytes = new BytesArray(Base64.getDecoder().decode("AAABBWluZGV4BHR5cGUCaWQBDHNvbWVfcm91dGluZwEOdGhlX3ByZWZlcmVuY2UEdGVybT" + "+AAAAABWZpZWxkFQV2YWx1ZQIGYWxpYXMwBmFsaWFzMQECBmZpZWxkMQZmaWVsZDIBAQEIZmllbGQxLioBCGZpZWxkMi4qAA"));
    try (StreamInput in = new NamedWriteableAwareStreamInput(requestBytes.streamInput(), namedWriteableRegistry)) {
        in.setVersion(Version.V_5_0_0);
        ExplainRequest readRequest = new ExplainRequest();
        readRequest.readFrom(in);
        assertEquals(0, in.available());
        assertArrayEquals(request.filteringAlias().getAliases(), readRequest.filteringAlias().getAliases());
        expectThrows(IllegalStateException.class, () -> readRequest.filteringAlias().getQueryBuilder());
        assertArrayEquals(request.storedFields(), readRequest.storedFields());
        assertEquals(request.preference(), readRequest.preference());
        assertEquals(request.query(), readRequest.query());
        assertEquals(request.routing(), readRequest.routing());
        assertEquals(request.fetchSourceContext(), readRequest.fetchSourceContext());
        BytesStreamOutput output = new BytesStreamOutput();
        output.setVersion(Version.V_5_0_0);
        readRequest.writeTo(output);
        assertEquals(output.bytes().toBytesRef(), requestBytes.toBytesRef());
    }
}
Also used : AliasFilter(org.elasticsearch.search.internal.AliasFilter) BytesArray(org.elasticsearch.common.bytes.BytesArray) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) ExplainRequest(org.elasticsearch.action.explain.ExplainRequest) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Aggregations

AliasFilter (org.elasticsearch.search.internal.AliasFilter)22 HashMap (java.util.HashMap)11 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)10 ShardId (org.elasticsearch.index.shard.ShardId)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ShardIterator (org.elasticsearch.cluster.routing.ShardIterator)6 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)6 NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)6 StreamInput (org.elasticsearch.common.io.stream.StreamInput)6 Set (java.util.Set)5 IOException (java.io.IOException)4 List (java.util.List)4 ActionListener (org.elasticsearch.action.ActionListener)4 GroupShardsIterator (org.elasticsearch.cluster.routing.GroupShardsIterator)4 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)4 Index (org.elasticsearch.index.Index)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 CountDownLatch (java.util.concurrent.CountDownLatch)3