org.elasticsearch.search.query.QueryPhaseExecutionException Java Examples
The following examples show how to use
org.elasticsearch.search.query.QueryPhaseExecutionException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSearchContext.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Should be called before executing the main query and after all other parameters have been set. */ @Override public void preProcess() { if (scrollContext == null) { long from = from() == -1 ? 0 : from(); long size = size() == -1 ? 10 : size(); long resultWindow = from + size; // We need settingsService's view of the settings because its dynamic. // indexService's isn't. int maxResultWindow = indexService.indexSettings().getAsInt(MAX_RESULT_WINDOW, Defaults.MAX_RESULT_WINDOW); if (resultWindow > maxResultWindow) { throw new QueryPhaseExecutionException(this, "Result window is too large, from + size must be less than or equal to: [" + maxResultWindow + "] but was [" + resultWindow + "]. See the scroll api for a more efficient way to request large data sets. " + "This limit can be set by changing the [" + DefaultSearchContext.MAX_RESULT_WINDOW + "] index level parameter."); } } // initialize the filtering alias based on the provided filters aliasFilter = indexService.aliasesService().aliasFilter(request.filteringAliases()); if (query() == null) { parsedQuery(ParsedQuery.parsedMatchAllQuery()); } if (queryBoost() != 1.0f) { parsedQuery(new ParsedQuery(new FunctionScoreQuery(query(), new BoostScoreFunction(queryBoost)), parsedQuery())); } filteredQuery(buildFilteredQuery()); try { this.query = searcher().rewrite(this.query); } catch (IOException e) { throw new QueryPhaseExecutionException(this, "Failed to rewrite main query", e); } }
Example #2
Source File: AbstractTransportExportAction.java From elasticsearch-inout-plugin with Apache License 2.0 | 5 votes |
@Override protected ShardExportResponse shardOperation(ShardExportRequest request) throws ElasticSearchException { IndexService indexService = indicesService.indexServiceSafe(request.index()); IndexShard indexShard = indexService.shardSafe(request.shardId()); SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().id(), request.index(), request.shardId()); ExportContext context = new ExportContext(0, new ShardSearchRequest().types(request.types()).filteringAliases(request.filteringAliases()), shardTarget, indexShard.searcher(), indexService, indexShard, scriptService, cacheRecycler, nodePath); ExportContext.setCurrent(context); try { BytesReference source = request.source(); exportParser.parseSource(context, source); context.preProcess(); exporter.check(context); try { if (context.explain()) { return new ShardExportResponse(shardTarget.nodeIdText(), request.index(), request.shardId(), context.outputCmd(), context.outputCmdArray(), context.outputFile()); } else { Exporter.Result res = exporter.execute(context); return new ShardExportResponse(shardTarget.nodeIdText(), request.index(), request.shardId(), context.outputCmd(), context.outputCmdArray(), context.outputFile(), res.outputResult.stdErr, res.outputResult.stdOut, res.outputResult.exit, res.numExported); } } catch (Exception e) { throw new QueryPhaseExecutionException(context, "failed to execute export", e); } } finally { // this will also release the index searcher context.release(); SearchContext.removeCurrent(); } }
Example #3
Source File: TransportExistsAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ShardExistsResponse shardOperation(ShardExistsRequest request) { IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(request.shardId().id()); SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().id(), request.shardId().getIndex(), request.shardId().id()); SearchContext context = new DefaultSearchContext(0, new ShardSearchLocalRequest(request.types(), request.nowInMillis(), request.filteringAliases()), shardTarget, indexShard.acquireSearcher("exists"), indexService, indexShard, scriptService, pageCacheRecycler, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, SearchService.NO_TIMEOUT ); SearchContext.setCurrent(context); try { if (request.minScore() != DEFAULT_MIN_SCORE) { context.minimumScore(request.minScore()); } BytesReference source = request.querySource(); if (source != null && source.length() > 0) { try { QueryParseContext.setTypes(request.types()); context.parsedQuery(indexService.queryParserService().parseQuery(source)); } finally { QueryParseContext.removeTypes(); } } context.preProcess(); try { boolean exists; try { exists = Lucene.exists(context.searcher(), context.query()); } finally { context.clearReleasables(SearchContext.Lifetime.COLLECTION); } return new ShardExistsResponse(request.shardId(), exists); } catch (Exception e) { throw new QueryPhaseExecutionException(context, "failed to execute exists", e); } } finally { // this will also release the index searcher context.close(); SearchContext.removeCurrent(); } }
Example #4
Source File: TransportTermsByQueryAction.java From siren-join with GNU Affero General Public License v3.0 | 4 votes |
/** * The operation that executes the query and generates a {@link TermsByQueryShardResponse} for each shard. */ @Override protected TermsByQueryShardResponse shardOperation(TermsByQueryShardRequest shardRequest) throws ElasticsearchException { IndexService indexService = indicesService.indexServiceSafe(shardRequest.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(shardRequest.shardId().id()); TermsByQueryRequest request = shardRequest.request(); OrderByShardOperation orderByOperation = OrderByShardOperation.get(request.getOrderBy(), request.maxTermsPerShard()); SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().id(), shardRequest.shardId().getIndex(), shardRequest.shardId().id()); ShardSearchRequest shardSearchRequest = new ShardSearchLocalRequest(request.types(), request.nowInMillis(), shardRequest.filteringAliases()); SearchContext context = new DefaultSearchContext(0, shardSearchRequest, shardTarget, indexShard.acquireSearcher("termsByQuery"), indexService, indexShard, scriptService, pageCacheRecycler, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, SearchService.NO_TIMEOUT); SearchContext.setCurrent(context); try { MappedFieldType fieldType = context.smartNameFieldType(request.field()); if (fieldType == null) { throw new SearchContextException(context, "[termsByQuery] field '" + request.field() + "' not found for types " + Arrays.toString(request.types())); } IndexFieldData indexFieldData = context.fieldData().getForField(fieldType); BytesReference querySource = request.querySource(); if (querySource != null && querySource.length() > 0) { XContentParser queryParser = null; try { queryParser = XContentFactory.xContent(querySource).createParser(querySource); QueryParseContext.setTypes(request.types()); ParsedQuery parsedQuery = orderByOperation.getParsedQuery(queryParser, indexService); if (parsedQuery != null) { context.parsedQuery(parsedQuery); } } finally { QueryParseContext.removeTypes(); if (queryParser != null) { queryParser.close(); } } } context.preProcess(); // execute the search only gathering the hit count and bitset for each segment logger.debug("{}: Executes search for collecting terms {}", Thread.currentThread().getName(), shardRequest.shardId()); TermsCollector termsCollector = this.getTermsCollector(request.termsEncoding(), indexFieldData, context); if (request.expectedTerms() != null) termsCollector.setExpectedTerms(request.expectedTerms()); if (request.maxTermsPerShard() != null) termsCollector.setMaxTerms(request.maxTermsPerShard()); HitStream hitStream = orderByOperation.getHitStream(context); TermsSet terms = termsCollector.collect(hitStream); logger.debug("{}: Returns terms response with {} terms for shard {}", Thread.currentThread().getName(), terms.size(), shardRequest.shardId()); return new TermsByQueryShardResponse(shardRequest.shardId(), terms); } catch (Throwable e) { logger.error("[termsByQuery] Error executing shard operation", e); throw new QueryPhaseExecutionException(context, "[termsByQuery] Failed to execute query", e); } finally { // this will also release the index searcher context.close(); SearchContext.removeCurrent(); } }
Example #5
Source File: AbstractTransportSearchIntoAction.java From elasticsearch-inout-plugin with Apache License 2.0 | 4 votes |
@Override protected ShardSearchIntoResponse shardOperation(ShardSearchIntoRequest request) throws ElasticSearchException { IndexService indexService = indicesService.indexServiceSafe( request.index()); IndexShard indexShard = indexService.shardSafe(request.shardId()); SearchShardTarget shardTarget = new SearchShardTarget( clusterService.localNode().id(), request.index(), request.shardId()); SearchIntoContext context = new SearchIntoContext(0, new ShardSearchRequest().types(request.types()).filteringAliases(request.filteringAliases()), shardTarget, indexShard.searcher(), indexService, indexShard, scriptService, cacheRecycler ); SearchIntoContext.setCurrent(context); try { BytesReference source = request.source(); parser.parseSource(context, source); context.preProcess(); try { if (context.explain()) { return new ShardSearchIntoResponse( shardTarget.nodeIdText(), request.index(), request.shardId()); } else { WriterResult res = writer.execute(context); return new ShardSearchIntoResponse( shardTarget.nodeIdText(), request.index(), request.shardId(), res); } } catch (Exception e) { throw new QueryPhaseExecutionException(context, "failed to execute inout", e); } } finally { // this will also release the index searcher context.release(); SearchContext.removeCurrent(); } }