Search in sources :

Example 1 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext 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 2 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class RestMultiSearchAction method parseRequest.

/**
     * Parses a {@link RestRequest} body and returns a {@link MultiSearchRequest}
     */
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
    MultiSearchRequest multiRequest = new MultiSearchRequest();
    if (restRequest.hasParam("max_concurrent_searches")) {
        multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));
    }
    parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, parser) -> {
        try {
            final QueryParseContext queryParseContext = new QueryParseContext(parser);
            searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext));
            multiRequest.add(searchRequest);
        } catch (IOException e) {
            throw new ElasticsearchParseException("Exception when parsing search request", e);
        }
    });
    return multiRequest;
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) IOException(java.io.IOException)

Example 3 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class RestSearchAction method parseSearchRequest.

/**
     * Parses the rest request on top of the SearchRequest, preserving values that are not overridden by the rest request.
     *
     * @param requestContentParser body of the request to read. This method does not attempt to read the body from the {@code request}
     *        parameter
     */
public static void parseSearchRequest(SearchRequest searchRequest, RestRequest request, XContentParser requestContentParser) throws IOException {
    if (searchRequest.source() == null) {
        searchRequest.source(new SearchSourceBuilder());
    }
    searchRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
    if (requestContentParser != null) {
        QueryParseContext context = new QueryParseContext(requestContentParser);
        searchRequest.source().parseXContent(context);
    }
    final int batchedReduceSize = request.paramAsInt("batched_reduce_size", searchRequest.getBatchedReduceSize());
    searchRequest.setBatchedReduceSize(batchedReduceSize);
    // do not allow 'query_and_fetch' or 'dfs_query_and_fetch' search types
    // from the REST layer. these modes are an internal optimization and should
    // not be specified explicitly by the user.
    String searchType = request.param("search_type");
    if ("query_and_fetch".equals(searchType) || "dfs_query_and_fetch".equals(searchType)) {
        throw new IllegalArgumentException("Unsupported search type [" + searchType + "]");
    } else {
        searchRequest.searchType(searchType);
    }
    parseSearchSource(searchRequest.source(), request);
    searchRequest.requestCache(request.paramAsBoolean("request_cache", null));
    String scroll = request.param("scroll");
    if (scroll != null) {
        searchRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
    }
    searchRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    searchRequest.routing(request.param("routing"));
    searchRequest.preference(request.param("preference"));
    searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) Scroll(org.elasticsearch.search.Scroll) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 4 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class GeoDistanceSortBuilderTests method testGeoDistanceSortCanBeParsedFromGeoHash.

public void testGeoDistanceSortCanBeParsedFromGeoHash() throws IOException {
    String json = "{\n" + "    \"VDcvDuFjE\" : [ \"7umzzv8eychg\", \"dmdgmt5z13uw\", " + "    \"ezu09wxw6v4c\", \"kc7s3515p6k6\", \"jgeuvjwrmfzn\", \"kcpcfj7ruyf8\" ],\n" + "    \"unit\" : \"m\",\n" + "    \"distance_type\" : \"arc\",\n" + "    \"mode\" : \"MAX\",\n" + "    \"nested_filter\" : {\n" + "      \"ids\" : {\n" + "        \"type\" : [ ],\n" + "        \"values\" : [ ],\n" + "        \"boost\" : 5.711116\n" + "      }\n" + "    },\n" + "    \"validation_method\" : \"STRICT\"\n" + "  }";
    XContentParser itemParser = createParser(JsonXContent.jsonXContent, json);
    itemParser.nextToken();
    QueryParseContext context = new QueryParseContext(itemParser);
    GeoDistanceSortBuilder result = GeoDistanceSortBuilder.fromXContent(context, json);
    assertEquals("[-19.700583312660456, -2.8225036337971687, " + "31.537466906011105, -74.63590376079082, " + "43.71844606474042, -5.548660643398762, " + "-37.20467280596495, 38.71751043945551, " + "-69.44606635719538, 84.25200328230858, " + "-39.03717711567879, 44.74099852144718]", Arrays.toString(result.points()));
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 5 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class GeoDistanceSortBuilderTests method parse.

private GeoDistanceSortBuilder parse(XContentBuilder sortBuilder) throws Exception {
    XContentParser parser = createParser(sortBuilder);
    QueryParseContext parseContext = new QueryParseContext(parser);
    parser.nextToken();
    return GeoDistanceSortBuilder.fromXContent(parseContext, null);
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

QueryParseContext (org.elasticsearch.index.query.QueryParseContext)55 XContentParser (org.elasticsearch.common.xcontent.XContentParser)45 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)14 ParsingException (org.elasticsearch.common.ParsingException)12 IOException (java.io.IOException)7 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)5 ArrayList (java.util.ArrayList)2 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)2 List (java.util.List)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 BytesReference (org.elasticsearch.common.bytes.BytesReference)2 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 SignificanceHeuristicParser (org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser)2 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude)2 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)2 SearchContext (org.elasticsearch.search.internal.SearchContext)2