diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java index d1405e92e1c..718d3b25e69 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java @@ -38,17 +38,11 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Randomness; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.index.IndexService; -import org.elasticsearch.index.engine.Engine; +import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.query.QueryShardException; -import org.elasticsearch.index.shard.IndexShard; -import org.elasticsearch.indices.IndicesService; -import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.SearchService; -import org.elasticsearch.search.fetch.FetchPhase; -import org.elasticsearch.search.internal.DefaultSearchContext; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.ShardSearchLocalRequest; import org.elasticsearch.tasks.Task; @@ -67,25 +61,15 @@ import java.util.concurrent.atomic.AtomicReferenceArray; */ public class TransportValidateQueryAction extends TransportBroadcastAction { - private final IndicesService indicesService; - - private final ScriptService scriptService; - - private final BigArrays bigArrays; - - private final FetchPhase fetchPhase; + private final SearchService searchService; @Inject public TransportValidateQueryAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, - TransportService transportService, IndicesService indicesService, ScriptService scriptService, - BigArrays bigArrays, ActionFilters actionFilters, - IndexNameExpressionResolver indexNameExpressionResolver, FetchPhase fetchPhase) { + TransportService transportService, SearchService searchService, ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, ValidateQueryAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver, ValidateQueryRequest::new, ShardValidateQueryRequest::new, ThreadPool.Names.SEARCH); - this.indicesService = indicesService; - this.scriptService = scriptService; - this.bigArrays = bigArrays; - this.fetchPhase = fetchPhase; + this.searchService = searchService; } @Override @@ -161,29 +145,20 @@ public class TransportValidateQueryAction extends TransportBroadcastAction SearchContext.removeCurrent()); } return new ShardValidateQueryResponse(request.shardId(), valid, explanation, error); } - private String getRewrittenQuery(IndexSearcher searcher, Query query) throws IOException { - Query queryRewrite = searcher.rewrite(query); - if (queryRewrite instanceof MatchNoDocsQuery) { - return query.toString(); + private String explain(SearchContext context, boolean rewritten) throws IOException { + Query query = context.query(); + if (rewritten && query instanceof MatchNoDocsQuery) { + return context.parsedQuery().query().toString(); } else { - return queryRewrite.toString(); + return query.toString(); } } } diff --git a/core/src/main/java/org/elasticsearch/action/explain/TransportExplainAction.java b/core/src/main/java/org/elasticsearch/action/explain/TransportExplainAction.java index 95177853d41..1ce2eafc843 100644 --- a/core/src/main/java/org/elasticsearch/action/explain/TransportExplainAction.java +++ b/core/src/main/java/org/elasticsearch/action/explain/TransportExplainAction.java @@ -31,20 +31,14 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.index.IndexService; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.get.GetResult; import org.elasticsearch.index.mapper.Uid; import org.elasticsearch.index.mapper.UidFieldMapper; -import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.indices.IndicesService; -import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.SearchService; -import org.elasticsearch.search.fetch.FetchPhase; -import org.elasticsearch.search.internal.DefaultSearchContext; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.ShardSearchLocalRequest; import org.elasticsearch.search.rescore.RescoreSearchContext; @@ -60,26 +54,15 @@ import java.io.IOException; // TODO: AggregatedDfs. Currently the idf can be different then when executing a normal search with explain. public class TransportExplainAction extends TransportSingleShardAction { - private final IndicesService indicesService; - - private final ScriptService scriptService; - - - private final BigArrays bigArrays; - - private final FetchPhase fetchPhase; + private final SearchService searchService; @Inject public TransportExplainAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, - TransportService transportService, IndicesService indicesService, ScriptService scriptService, - BigArrays bigArrays, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, - FetchPhase fetchPhase) { + TransportService transportService, SearchService searchService, ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, ExplainAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver, ExplainRequest::new, ThreadPool.Names.GET); - this.indicesService = indicesService; - this.scriptService = scriptService; - this.bigArrays = bigArrays; - this.fetchPhase = fetchPhase; + this.searchService = searchService; } @Override @@ -104,23 +87,19 @@ public class TransportExplainAction extends TransportSingleShardAction SearchContext.removeCurrent()); } } diff --git a/core/src/main/java/org/elasticsearch/action/get/GetRequest.java b/core/src/main/java/org/elasticsearch/action/get/GetRequest.java index 42c4ccc701d..76de3bbd4b6 100644 --- a/core/src/main/java/org/elasticsearch/action/get/GetRequest.java +++ b/core/src/main/java/org/elasticsearch/action/get/GetRequest.java @@ -61,7 +61,6 @@ public class GetRequest extends SingleShardRequest implements Realti private VersionType versionType = VersionType.INTERNAL; private long version = Versions.MATCH_ANY; - private boolean ignoreErrorsOnGeneratedFields; public GetRequest() { type = "_all"; @@ -248,19 +247,10 @@ public class GetRequest extends SingleShardRequest implements Realti return this; } - public GetRequest ignoreErrorsOnGeneratedFields(boolean ignoreErrorsOnGeneratedFields) { - this.ignoreErrorsOnGeneratedFields = ignoreErrorsOnGeneratedFields; - return this; - } - public VersionType versionType() { return this.versionType; } - public boolean ignoreErrorsOnGeneratedFields() { - return ignoreErrorsOnGeneratedFields; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); @@ -278,7 +268,6 @@ public class GetRequest extends SingleShardRequest implements Realti } } realtime = in.readBoolean(); - this.ignoreErrorsOnGeneratedFields = in.readBoolean(); this.versionType = VersionType.fromValue(in.readByte()); this.version = in.readLong(); @@ -304,7 +293,6 @@ public class GetRequest extends SingleShardRequest implements Realti } } out.writeBoolean(realtime); - out.writeBoolean(ignoreErrorsOnGeneratedFields); out.writeByte(versionType.getValue()); out.writeLong(version); out.writeOptionalStreamable(fetchSourceContext); diff --git a/core/src/main/java/org/elasticsearch/action/get/GetRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/get/GetRequestBuilder.java index 7827de12eac..a3f070fd2ef 100644 --- a/core/src/main/java/org/elasticsearch/action/get/GetRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/get/GetRequestBuilder.java @@ -155,11 +155,6 @@ public class GetRequestBuilder extends SingleShardOperationRequestBuilder implements I String preference; boolean realtime = true; boolean refresh; - public boolean ignoreErrorsOnGeneratedFields = false; - List items = new ArrayList<>(); public List getItems() { @@ -338,11 +336,6 @@ public class MultiGetRequest extends ActionRequest implements I } - public MultiGetRequest ignoreErrorsOnGeneratedFields(boolean ignoreErrorsOnGeneratedFields) { - this.ignoreErrorsOnGeneratedFields = ignoreErrorsOnGeneratedFields; - return this; - } - public MultiGetRequest add(@Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSource, byte[] data, int from, int length) throws Exception { return add(defaultIndex, defaultType, defaultFields, defaultFetchSource, new BytesArray(data, from, length), true); } @@ -510,7 +503,6 @@ public class MultiGetRequest extends ActionRequest implements I preference = in.readOptionalString(); refresh = in.readBoolean(); realtime = in.readBoolean(); - ignoreErrorsOnGeneratedFields = in.readBoolean(); int size = in.readVInt(); items = new ArrayList<>(size); @@ -525,7 +517,6 @@ public class MultiGetRequest extends ActionRequest implements I out.writeOptionalString(preference); out.writeBoolean(refresh); out.writeBoolean(realtime); - out.writeBoolean(ignoreErrorsOnGeneratedFields); out.writeVInt(items.size()); for (Item item : items) { diff --git a/core/src/main/java/org/elasticsearch/action/get/MultiGetRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/get/MultiGetRequestBuilder.java index 6e32e1caf30..a2cb204d5ea 100644 --- a/core/src/main/java/org/elasticsearch/action/get/MultiGetRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/get/MultiGetRequestBuilder.java @@ -80,9 +80,4 @@ public class MultiGetRequestBuilder extends ActionRequestBuilder items; @@ -52,7 +51,6 @@ public class MultiGetShardRequest extends SingleShardRequest) () -> new ParameterizedMessage("{} failed to execute multi_get for [{}]/[{}]", shardId, item.type(), item.id()), e); + logger.debug((Supplier) () -> new ParameterizedMessage("{} failed to execute multi_get for [{}]/[{}]", shardId, + item.type(), item.id()), e); response.add(request.locations.get(i), new MultiGetResponse.Failure(request.index(), item.type(), item.id(), e)); } } diff --git a/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java index d86134c7d44..6cb68b8e9be 100644 --- a/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java @@ -40,8 +40,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.search.SearchPhaseResult; import org.elasticsearch.search.SearchShardTarget; -import org.elasticsearch.search.action.SearchTransportService; -import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.fetch.ShardFetchSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.search.internal.ShardSearchTransportRequest; diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryAndFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryAndFetchAsyncAction.java index 367832afab3..ba73b0f4bea 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryAndFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryAndFetchAsyncAction.java @@ -28,8 +28,6 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.util.concurrent.AtomicArray; -import org.elasticsearch.search.action.SearchTransportService; -import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.dfs.AggregatedDfs; import org.elasticsearch.search.dfs.DfsSearchResult; import org.elasticsearch.search.fetch.QueryFetchSearchResult; diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java index 7ceefb1998c..ccd646ae129 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java @@ -31,8 +31,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.search.SearchShardTarget; -import org.elasticsearch.search.action.SearchTransportService; -import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.dfs.AggregatedDfs; import org.elasticsearch.search.dfs.DfsSearchResult; import org.elasticsearch.search.fetch.FetchSearchResult; diff --git a/core/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java similarity index 99% rename from core/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java rename to core/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java index 1766d41dde3..7306e645e0d 100644 --- a/core/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.controller; +package org.elasticsearch.action.search; import com.carrotsearch.hppc.IntArrayList; import com.carrotsearch.hppc.ObjectObjectHashMap; @@ -89,8 +89,7 @@ public class SearchPhaseController extends AbstractComponent { private final ScriptService scriptService; private final ClusterService clusterService; - @Inject - public SearchPhaseController(Settings settings, BigArrays bigArrays, ScriptService scriptService, ClusterService clusterService) { + SearchPhaseController(Settings settings, BigArrays bigArrays, ScriptService scriptService, ClusterService clusterService) { super(settings); this.bigArrays = bigArrays; this.scriptService = scriptService; diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchQueryAndFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchQueryAndFetchAsyncAction.java index 2e13a0d26e8..d799bc26764 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchQueryAndFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchQueryAndFetchAsyncAction.java @@ -25,8 +25,6 @@ import org.elasticsearch.action.ActionRunnable; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.search.action.SearchTransportService; -import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.fetch.QueryFetchSearchResult; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.search.internal.ShardSearchTransportRequest; diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java index 3987b48c561..6df2bb3f87e 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java @@ -31,8 +31,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.search.SearchShardTarget; -import org.elasticsearch.search.action.SearchTransportService; -import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.fetch.FetchSearchResult; import org.elasticsearch.search.fetch.ShardFetchSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryAndFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryAndFetchAsyncAction.java index 24e497954a7..2bdf7dc30f9 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryAndFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryAndFetchAsyncAction.java @@ -28,8 +28,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.util.concurrent.AtomicArray; -import org.elasticsearch.search.action.SearchTransportService; -import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.fetch.QueryFetchSearchResult; import org.elasticsearch.search.fetch.ScrollQueryFetchSearchResult; import org.elasticsearch.search.internal.InternalScrollSearchRequest; diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryThenFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryThenFetchAsyncAction.java index 21f1c4ce68a..4024d3b5f39 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryThenFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryThenFetchAsyncAction.java @@ -29,8 +29,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.util.concurrent.AtomicArray; -import org.elasticsearch.search.action.SearchTransportService; -import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.fetch.FetchSearchResult; import org.elasticsearch.search.fetch.ShardFetchRequest; import org.elasticsearch.search.internal.InternalScrollSearchRequest; diff --git a/core/src/main/java/org/elasticsearch/search/action/SearchTransportService.java b/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java similarity index 98% rename from core/src/main/java/org/elasticsearch/search/action/SearchTransportService.java rename to core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java index 8552d21b5c3..985cc854f05 100644 --- a/core/src/main/java/org/elasticsearch/search/action/SearchTransportService.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java @@ -17,17 +17,15 @@ * under the License. */ -package org.elasticsearch.search.action; +package org.elasticsearch.action.search; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListenerResponseHandler; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.OriginalIndices; -import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; @@ -75,8 +73,7 @@ public class SearchTransportService extends AbstractComponent { private final TransportService transportService; private final SearchService searchService; - @Inject - public SearchTransportService(Settings settings, TransportService transportService, SearchService searchService) { + SearchTransportService(Settings settings, TransportService transportService, SearchService searchService) { super(settings); this.transportService = transportService; this.searchService = searchService; diff --git a/core/src/main/java/org/elasticsearch/action/search/TransportClearScrollAction.java b/core/src/main/java/org/elasticsearch/action/search/TransportClearScrollAction.java index 220e7f5b250..cb7e7531d2d 100644 --- a/core/src/main/java/org/elasticsearch/action/search/TransportClearScrollAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/TransportClearScrollAction.java @@ -32,7 +32,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.CountDown; -import org.elasticsearch.search.action.SearchTransportService; +import org.elasticsearch.search.SearchService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportResponse; import org.elasticsearch.transport.TransportService; @@ -53,11 +53,11 @@ public class TransportClearScrollAction extends HandledTransportAction searchServiceImpl = pickSearchServiceImplementation(); - if (searchServiceImpl == SearchService.class) { - b.bind(SearchService.class).asEagerSingleton(); - } else { - b.bind(SearchService.class).to(searchServiceImpl).asEagerSingleton(); - } + b.bind(SearchService.class).toInstance(newSearchService(clusterService, indicesService, + threadPool, scriptModule.getScriptService(), bigArrays, searchModule.getFetchPhase())); pluginComponents.stream().forEach(p -> b.bind((Class) p.getClass()).toInstance(p)); } @@ -793,10 +787,12 @@ public class Node implements Closeable { } /** - * Select the search service implementation. Overrided by tests. + * Creates a new the SearchService. This method can be overwritten by tests to inject mock implementations. */ - protected Class pickSearchServiceImplementation() { - return SearchService.class; + protected SearchService newSearchService(ClusterService clusterService, IndicesService indicesService, + ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, + FetchPhase fetchPhase) { + return new SearchService(clusterService, indicesService, threadPool, scriptService, bigArrays, fetchPhase); } /** diff --git a/core/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java b/core/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java index 8c782a8d128..f127a58579e 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java @@ -58,7 +58,6 @@ public class RestGetAction extends BaseRestHandler { getRequest.parent(request.param("parent")); getRequest.preference(request.param("preference")); getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime())); - getRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false)); String sField = request.param("fields"); if (sField != null) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java b/core/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java index 995c43059da..50bd4c37ac7 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java @@ -59,7 +59,6 @@ public class RestMultiGetAction extends BaseRestHandler { multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh())); multiGetRequest.preference(request.param("preference")); multiGetRequest.realtime(request.paramAsBoolean("realtime", multiGetRequest.realtime())); - multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false)); String[] sFields = null; String sField = request.param("fields"); diff --git a/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java b/core/src/main/java/org/elasticsearch/search/DefaultSearchContext.java similarity index 95% rename from core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java rename to core/src/main/java/org/elasticsearch/search/DefaultSearchContext.java index b1618c3a205..20789e015a9 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/DefaultSearchContext.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.internal; +package org.elasticsearch.search; import org.apache.lucene.queries.TermsQuery; import org.apache.lucene.search.BooleanClause.Occur; @@ -53,8 +53,6 @@ import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.SearchExtBuilder; -import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.aggregations.SearchContextAggregations; import org.elasticsearch.search.dfs.DfsSearchResult; import org.elasticsearch.search.fetch.FetchPhase; @@ -64,6 +62,10 @@ import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext; import org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight; +import org.elasticsearch.search.internal.ContextIndexSearcher; +import org.elasticsearch.search.internal.ScrollContext; +import org.elasticsearch.search.internal.SearchContext; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.search.profile.Profilers; import org.elasticsearch.search.query.QueryPhaseExecutionException; @@ -80,7 +82,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class DefaultSearchContext extends SearchContext { +final class DefaultSearchContext extends SearchContext { private final long id; private final ShardSearchRequest request; @@ -123,10 +125,7 @@ public class DefaultSearchContext extends SearchContext { * things like the type filter or alias filters. */ private ParsedQuery originalQuery; - /** - * Just like originalQuery but with the filters from types, aliases and slice applied. - */ - private ParsedQuery filteredQuery; + /** * The query to actually execute. */ @@ -151,7 +150,7 @@ public class DefaultSearchContext extends SearchContext { private final QueryShardContext queryShardContext; private FetchPhase fetchPhase; - public DefaultSearchContext(long id, ShardSearchRequest request, SearchShardTarget shardTarget, Engine.Searcher engineSearcher, + DefaultSearchContext(long id, ShardSearchRequest request, SearchShardTarget shardTarget, Engine.Searcher engineSearcher, IndexService indexService, IndexShard indexShard, ScriptService scriptService, BigArrays bigArrays, Counter timeEstimateCounter, ParseFieldMatcher parseFieldMatcher, TimeValue timeout, FetchPhase fetchPhase) { @@ -187,7 +186,7 @@ public class DefaultSearchContext extends SearchContext { * Should be called before executing the main query and after all other parameters have been set. */ @Override - public void preProcess() { + public void preProcess(boolean rewrite) { if (hasOnlySuggest() ) { return; } @@ -241,20 +240,22 @@ public class DefaultSearchContext extends SearchContext { if (queryBoost() != AbstractQueryBuilder.DEFAULT_BOOST) { parsedQuery(new ParsedQuery(new FunctionScoreQuery(query(), new WeightFactorFunction(queryBoost)), parsedQuery())); } - filteredQuery(buildFilteredQuery()); - try { - this.query = searcher().rewrite(this.query); - } catch (IOException e) { - throw new QueryPhaseExecutionException(this, "Failed to rewrite main query", e); + this.query = buildFilteredQuery(); + if (rewrite) { + try { + this.query = searcher.rewrite(query); + } catch (IOException e) { + throw new QueryPhaseExecutionException(this, "Failed to rewrite main query", e); + } } } - private ParsedQuery buildFilteredQuery() { - Query searchFilter = searchFilter(queryShardContext.getTypes()); + private Query buildFilteredQuery() { + final Query searchFilter = searchFilter(queryShardContext.getTypes()); if (searchFilter == null) { - return originalQuery; + return originalQuery.query(); } - Query result; + final Query result; if (Queries.isConstantMatchAllQuery(query())) { result = new ConstantScoreQuery(searchFilter); } else { @@ -263,7 +264,7 @@ public class DefaultSearchContext extends SearchContext { .add(searchFilter, Occur.FILTER) .build(); } - return new ParsedQuery(result, originalQuery); + return result; } @Override @@ -618,15 +619,6 @@ public class DefaultSearchContext extends SearchContext { return this; } - public ParsedQuery filteredQuery() { - return filteredQuery; - } - - private void filteredQuery(ParsedQuery filteredQuery) { - this.filteredQuery = filteredQuery; - this.query = filteredQuery.query(); - } - @Override public ParsedQuery parsedQuery() { return this.originalQuery; diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 0a1d9824ea9..ec9f33e6c19 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -95,7 +95,6 @@ import org.elasticsearch.plugins.SearchPlugin.QuerySpec; import org.elasticsearch.plugins.SearchPlugin.ScoreFunctionSpec; import org.elasticsearch.plugins.SearchPlugin.SearchExtSpec; import org.elasticsearch.plugins.SearchPlugin.SearchExtensionSpec; -import org.elasticsearch.search.action.SearchTransportService; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorParsers; @@ -243,7 +242,6 @@ import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel; import org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel; import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator; -import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.fetch.FetchPhase; import org.elasticsearch.search.fetch.FetchSubPhase; import org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase; @@ -384,7 +382,6 @@ public class SearchModule extends AbstractModule { bind(IndicesQueriesRegistry.class).toInstance(queryParserRegistry); bind(SearchRequestParsers.class).toInstance(searchRequestParsers); bind(SearchExtRegistry.class).toInstance(searchExtParserRegistry); - configureSearch(); } } @@ -574,13 +571,6 @@ public class SearchModule extends AbstractModule { } } - protected void configureSearch() { - // configure search private classes... - bind(SearchPhaseController.class).asEagerSingleton(); - bind(FetchPhase.class).toInstance(new FetchPhase(fetchSubPhases)); - bind(SearchTransportService.class).asEagerSingleton(); - } - private void registerShapes() { if (ShapesAvailability.JTS_AVAILABLE && ShapesAvailability.SPATIAL4J_AVAILABLE) { ShapeBuilders.register(namedWriteables); @@ -817,4 +807,8 @@ public class SearchModule extends AbstractModule { queryParserRegistry.register(spec.getParser(), spec.getName()); namedWriteables.add(new Entry(QueryBuilder.class, spec.getName().getPreferredName(), spec.getReader())); } + + public FetchPhase getFetchPhase() { + return new FetchPhase(fetchSubPhases); + } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index 2fb87565aa3..4334c5cf541 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -29,9 +29,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; @@ -66,7 +64,6 @@ import org.elasticsearch.search.fetch.ShardFetchRequest; import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext; import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; -import org.elasticsearch.search.internal.DefaultSearchContext; import org.elasticsearch.search.internal.InternalScrollSearchRequest; import org.elasticsearch.search.internal.ScrollContext; import org.elasticsearch.search.internal.SearchContext; @@ -141,10 +138,9 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv private final ParseFieldMatcher parseFieldMatcher; - @Inject - public SearchService(Settings settings, ClusterSettings clusterSettings, ClusterService clusterService, IndicesService indicesService, + public SearchService(ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase) { - super(settings); + super(clusterService.getSettings()); this.parseFieldMatcher = new ParseFieldMatcher(settings); this.threadPool = threadPool; this.clusterService = clusterService; @@ -160,7 +156,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv this.keepAliveReaper = threadPool.scheduleWithFixedDelay(new Reaper(), keepAliveInterval, Names.SAME); defaultSearchTimeout = DEFAULT_SEARCH_TIMEOUT_SETTING.get(settings); - clusterSettings.addSettingsUpdateConsumer(DEFAULT_SEARCH_TIMEOUT_SETTING, this::setDefaultSearchTimeout); + clusterService.getClusterSettings().addSettingsUpdateConsumer(DEFAULT_SEARCH_TIMEOUT_SETTING, this::setDefaultSearchTimeout); } private void setDefaultSearchTimeout(TimeValue defaultSearchTimeout) { @@ -520,16 +516,8 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv } final SearchContext createContext(ShardSearchRequest request, @Nullable Engine.Searcher searcher) throws IOException { - IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); - IndexShard indexShard = indexService.getShard(request.shardId().getId()); - SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().getId(), indexShard.shardId()); - Engine.Searcher engineSearcher = searcher == null ? indexShard.acquireSearcher("search") : searcher; - - DefaultSearchContext context = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, - indexService, - indexShard, scriptService, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, - defaultSearchTimeout, fetchPhase); + DefaultSearchContext context = createSearchContext(request, defaultSearchTimeout, searcher); SearchContext.setCurrent(context); try { request.rewrite(context.getQueryShardContext()); @@ -572,6 +560,18 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv return context; } + public DefaultSearchContext createSearchContext(ShardSearchRequest request, TimeValue timeout, @Nullable Engine.Searcher searcher) { + IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); + IndexShard indexShard = indexService.getShard(request.shardId().getId()); + SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().getId(), indexShard.shardId()); + Engine.Searcher engineSearcher = searcher == null ? indexShard.acquireSearcher("search") : searcher; + + return new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, + indexService, + indexShard, scriptService, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, + timeout, fetchPhase); + } + private void freeAllContextForIndex(Index index) { assert index != null; for (SearchContext ctx : activeContexts.values()) { diff --git a/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java index 18af4873db3..04156bfac2d 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java @@ -100,8 +100,8 @@ public abstract class FilteredSearchContext extends SearchContext { } @Override - public void preProcess() { - in.preProcess(); + public void preProcess(boolean rewrite) { + in.preProcess(rewrite); } @Override diff --git a/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java index e96c9856a33..459df14a357 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java @@ -139,8 +139,9 @@ public abstract class SearchContext extends AbstractRefCounted implements Releas /** * Should be called before executing the main query and after all other parameters have been set. + * @param rewrite if the set query should be rewritten against the searcher returned from {@link #searcher()} */ - public abstract void preProcess(); + public abstract void preProcess(boolean rewrite); public abstract Query searchFilter(String[] types); diff --git a/core/src/main/java/org/elasticsearch/search/internal/ShardSearchLocalRequest.java b/core/src/main/java/org/elasticsearch/search/internal/ShardSearchLocalRequest.java index d025d573c14..0d6148011ed 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/ShardSearchLocalRequest.java +++ b/core/src/main/java/org/elasticsearch/search/internal/ShardSearchLocalRequest.java @@ -81,14 +81,11 @@ public class ShardSearchLocalRequest implements ShardSearchRequest { this.nowInMillis = nowInMillis; } - public ShardSearchLocalRequest(String[] types, long nowInMillis) { + public ShardSearchLocalRequest(ShardId shardId, String[] types, long nowInMillis, String[] filteringAliases) { this.types = types; this.nowInMillis = nowInMillis; - } - - public ShardSearchLocalRequest(String[] types, long nowInMillis, String[] filteringAliases) { - this(types, nowInMillis); this.filteringAliases = filteringAliases; + this.shardId = shardId; } public ShardSearchLocalRequest(ShardId shardId, int numberOfShards, SearchType searchType, SearchSourceBuilder source, String[] types, diff --git a/core/src/main/java/org/elasticsearch/search/internal/SubSearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/SubSearchContext.java index dc385a0e120..2eb2d34dd2c 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/SubSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/SubSearchContext.java @@ -77,7 +77,7 @@ public class SubSearchContext extends FilteredSearchContext { } @Override - public void preProcess() { + public void preProcess(boolean rewrite) { } @Override diff --git a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java index 47fa98856cf..d1e90b2e9a5 100644 --- a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java +++ b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java @@ -85,7 +85,7 @@ public class QueryPhase implements SearchPhase { @Override public void preProcess(SearchContext context) { - context.preProcess(); + context.preProcess(true); } @Override diff --git a/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java b/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java index 1a11e3f4803..5b901536471 100644 --- a/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java +++ b/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java @@ -86,7 +86,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.action.SearchTransportService; +import org.elasticsearch.action.search.SearchTransportService; import org.elasticsearch.tasks.Task; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; diff --git a/core/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java b/core/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java index dab737cf7f5..eed5f85c4a4 100644 --- a/core/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java @@ -42,8 +42,6 @@ public class MultiGetShardRequestTests extends ESTestCase { if (randomBoolean()) { multiGetRequest.refresh(true); } - multiGetRequest.ignoreErrorsOnGeneratedFields(randomBoolean()); - MultiGetShardRequest multiGetShardRequest = new MultiGetShardRequest(multiGetRequest, "index", 0); int numItems = iterations(10, 30); for (int i = 0; i < numItems; i++) { @@ -79,7 +77,6 @@ public class MultiGetShardRequestTests extends ESTestCase { assertThat(multiGetShardRequest2.preference(), equalTo(multiGetShardRequest.preference())); assertThat(multiGetShardRequest2.realtime(), equalTo(multiGetShardRequest.realtime())); assertThat(multiGetShardRequest2.refresh(), equalTo(multiGetShardRequest.refresh())); - assertThat(multiGetShardRequest2.ignoreErrorsOnGeneratedFields(), equalTo(multiGetShardRequest.ignoreErrorsOnGeneratedFields())); assertThat(multiGetShardRequest2.items.size(), equalTo(multiGetShardRequest.items.size())); for (int i = 0; i < multiGetShardRequest2.items.size(); i++) { MultiGetRequest.Item item = multiGetShardRequest.items.get(i); diff --git a/core/src/test/java/org/elasticsearch/search/controller/SearchPhaseControllerTests.java b/core/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java similarity index 99% rename from core/src/test/java/org/elasticsearch/search/controller/SearchPhaseControllerTests.java rename to core/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java index 33ef23db6ed..2778a9dbf47 100644 --- a/core/src/test/java/org/elasticsearch/search/controller/SearchPhaseControllerTests.java +++ b/core/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.search.controller; +package org.elasticsearch.action.search; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; +import org.elasticsearch.action.search.SearchPhaseController; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.util.BigArrays; diff --git a/core/src/test/java/org/elasticsearch/get/GetActionIT.java b/core/src/test/java/org/elasticsearch/get/GetActionIT.java index 25c0e616090..052fa91d876 100644 --- a/core/src/test/java/org/elasticsearch/get/GetActionIT.java +++ b/core/src/test/java/org/elasticsearch/get/GetActionIT.java @@ -930,36 +930,30 @@ public class GetActionIT extends ESIntegTestCase { private void assertGetFieldsAlwaysWorks(String index, String type, String docId, String[] fields, @Nullable String routing) { for (String field : fields) { - assertGetFieldWorks(index, type, docId, field, false, routing); - assertGetFieldWorks(index, type, docId, field, true, routing); + assertGetFieldWorks(index, type, docId, field, routing); + assertGetFieldWorks(index, type, docId, field, routing); } } - private void assertGetFieldWorks(String index, String type, String docId, String field, boolean ignoreErrors, @Nullable String routing) { - GetResponse response = getDocument(index, type, docId, field, ignoreErrors, routing); + private void assertGetFieldWorks(String index, String type, String docId, String field, @Nullable String routing) { + GetResponse response = getDocument(index, type, docId, field, routing); assertThat(response.getId(), equalTo(docId)); assertTrue(response.isExists()); assertNotNull(response.getField(field)); - response = multiGetDocument(index, type, docId, field, ignoreErrors, routing); + response = multiGetDocument(index, type, docId, field, routing); assertThat(response.getId(), equalTo(docId)); assertTrue(response.isExists()); assertNotNull(response.getField(field)); } - protected void assertGetFieldsException(String index, String type, String docId, String[] fields) { - for (String field : fields) { - assertGetFieldException(index, type, docId, field); - } - } - private void assertGetFieldException(String index, String type, String docId, String field) { try { - client().prepareGet().setIndex(index).setType(type).setId(docId).setFields(field).setIgnoreErrorsOnGeneratedFields(false).get(); + client().prepareGet().setIndex(index).setType(type).setId(docId).setFields(field).get(); fail(); } catch (ElasticsearchException e) { assertTrue(e.getMessage().contains("You can only get this field after refresh() has been called.")); } - MultiGetResponse multiGetResponse = client().prepareMultiGet().add(new MultiGetRequest.Item(index, type, docId).fields(field)).setIgnoreErrorsOnGeneratedFields(false).get(); + MultiGetResponse multiGetResponse = client().prepareMultiGet().add(new MultiGetRequest.Item(index, type, docId).fields(field)).get(); assertNull(multiGetResponse.getResponses()[0].getResponse()); assertTrue(multiGetResponse.getResponses()[0].getFailure().getMessage().contains("You can only get this field after refresh() has been called.")); } @@ -970,7 +964,7 @@ public class GetActionIT extends ESIntegTestCase { protected void assertGetFieldsNull(String index, String type, String docId, String[] fields, @Nullable String routing) { for (String field : fields) { - assertGetFieldNull(index, type, docId, field, true, routing); + assertGetFieldNull(index, type, docId, field, routing); } } @@ -980,37 +974,37 @@ public class GetActionIT extends ESIntegTestCase { protected void assertGetFieldsAlwaysNull(String index, String type, String docId, String[] fields, @Nullable String routing) { for (String field : fields) { - assertGetFieldNull(index, type, docId, field, true, routing); - assertGetFieldNull(index, type, docId, field, false, routing); + assertGetFieldNull(index, type, docId, field, routing); + assertGetFieldNull(index, type, docId, field, routing); } } - protected void assertGetFieldNull(String index, String type, String docId, String field, boolean ignoreErrors, @Nullable String routing) { + protected void assertGetFieldNull(String index, String type, String docId, String field, @Nullable String routing) { //for get - GetResponse response = getDocument(index, type, docId, field, ignoreErrors, routing); + GetResponse response = getDocument(index, type, docId, field, routing); assertTrue(response.isExists()); assertNull(response.getField(field)); assertThat(response.getId(), equalTo(docId)); //same for multi get - response = multiGetDocument(index, type, docId, field, ignoreErrors, routing); + response = multiGetDocument(index, type, docId, field, routing); assertNull(response.getField(field)); assertThat(response.getId(), equalTo(docId)); assertTrue(response.isExists()); } - private GetResponse multiGetDocument(String index, String type, String docId, String field, boolean ignoreErrors, @Nullable String routing) { + private GetResponse multiGetDocument(String index, String type, String docId, String field, @Nullable String routing) { MultiGetRequest.Item getItem = new MultiGetRequest.Item(index, type, docId).fields(field); if (routing != null) { getItem.routing(routing); } - MultiGetRequestBuilder multiGetRequestBuilder = client().prepareMultiGet().add(getItem).setIgnoreErrorsOnGeneratedFields(ignoreErrors); + MultiGetRequestBuilder multiGetRequestBuilder = client().prepareMultiGet().add(getItem); MultiGetResponse multiGetResponse = multiGetRequestBuilder.get(); assertThat(multiGetResponse.getResponses().length, equalTo(1)); return multiGetResponse.getResponses()[0].getResponse(); } - private GetResponse getDocument(String index, String type, String docId, String field, boolean ignoreErrors, @Nullable String routing) { - GetRequestBuilder getRequestBuilder = client().prepareGet().setIndex(index).setType(type).setId(docId).setFields(field).setIgnoreErrorsOnGeneratedFields(ignoreErrors); + private GetResponse getDocument(String index, String type, String docId, String field, @Nullable String routing) { + GetRequestBuilder getRequestBuilder = client().prepareGet().setIndex(index).setType(type).setId(docId).setFields(field); if (routing != null) { getRequestBuilder.setRouting(routing); } diff --git a/core/src/test/java/org/elasticsearch/search/internal/DefaultSearchContextTests.java b/core/src/test/java/org/elasticsearch/search/DefaultSearchContextTests.java similarity index 97% rename from core/src/test/java/org/elasticsearch/search/internal/DefaultSearchContextTests.java rename to core/src/test/java/org/elasticsearch/search/DefaultSearchContextTests.java index 9ab5af9f393..e546130b2e5 100644 --- a/core/src/test/java/org/elasticsearch/search/internal/DefaultSearchContextTests.java +++ b/core/src/test/java/org/elasticsearch/search/DefaultSearchContextTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.internal; +package org.elasticsearch.search; import org.apache.lucene.queries.TermsQuery; import org.apache.lucene.search.BooleanQuery; @@ -26,6 +26,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.index.mapper.TypeFieldMapper; +import org.elasticsearch.search.DefaultSearchContext; import org.elasticsearch.test.ESTestCase; import static org.apache.lucene.search.BooleanClause.Occur.FILTER; diff --git a/core/src/test/java/org/elasticsearch/search/SearchRequestTests.java b/core/src/test/java/org/elasticsearch/search/SearchRequestTests.java index 548a09d37bc..2c7ae356bf8 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchRequestTests.java +++ b/core/src/test/java/org/elasticsearch/search/SearchRequestTests.java @@ -56,12 +56,7 @@ public class SearchRequestTests extends ESTestCase { } }; SearchModule searchModule = new SearchModule(Settings.EMPTY, false, - Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin())) { - @Override - protected void configureSearch() { - // Skip me - } - }; + Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin())); List entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables()); entries.addAll(searchModule.getNamedWriteables()); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java index a7476381b8e..b23bce86b4e 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java @@ -119,12 +119,7 @@ public class AggregatorParsingTests extends ESTestCase { bindMapperExtension(); } }; - SearchModule searchModule = new SearchModule(settings, false, emptyList()) { - @Override - protected void configureSearch() { - // Skip me - } - }; + SearchModule searchModule = new SearchModule(settings, false, emptyList()); List entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables()); entries.addAll(searchModule.getNamedWriteables()); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index b9c0e5f09c1..2cc1ca04f4d 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -143,12 +143,7 @@ public abstract class BaseAggregationTestCase entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables()); entries.addAll(searchModule.getNamedWriteables()); diff --git a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java index 7960e9bf4e8..0ecb50d584e 100644 --- a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java @@ -133,12 +133,7 @@ public class SearchSourceBuilderTests extends ESTestCase { } }; SearchModule searchModule = new SearchModule(settings, false, - Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin())) { - @Override - protected void configureSearch() { - // Skip me - } - }; + Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin())); List entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables()); entries.addAll(searchModule.getNamedWriteables()); diff --git a/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java b/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java index eb37299306c..99a2b438ffd 100644 --- a/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java +++ b/core/src/test/java/org/elasticsearch/search/internal/ShardSearchTransportRequestTests.java @@ -59,12 +59,7 @@ public class ShardSearchTransportRequestTests extends ESTestCase { } }; SearchModule searchModule = new SearchModule(Settings.EMPTY, false, - Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin())) { - @Override - protected void configureSearch() { - // Skip me - } - }; + Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin())); List entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables()); entries.addAll(searchModule.getNamedWriteables()); diff --git a/test/framework/src/main/java/org/elasticsearch/node/MockNode.java b/test/framework/src/main/java/org/elasticsearch/node/MockNode.java index 37da93b8257..a1be5769b61 100644 --- a/test/framework/src/main/java/org/elasticsearch/node/MockNode.java +++ b/test/framework/src/main/java/org/elasticsearch/node/MockNode.java @@ -19,18 +19,21 @@ package org.elasticsearch.node; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.MockBigArrays; +import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.SearchPlugin; +import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.MockSearchService; import org.elasticsearch.search.SearchService; +import org.elasticsearch.search.fetch.FetchPhase; +import org.elasticsearch.threadpool.ThreadPool; import java.util.Collection; -import java.util.List; /** * A node for testing which allows: @@ -62,11 +65,15 @@ public class MockNode extends Node { return new MockBigArrays(settings, circuitBreakerService); } + @Override - protected Class pickSearchServiceImplementation() { + protected SearchService newSearchService(ClusterService clusterService, IndicesService indicesService, + ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, + FetchPhase fetchPhase) { if (getPluginsService().filterPlugins(MockSearchService.TestPlugin.class).isEmpty()) { - return super.pickSearchServiceImplementation(); + return super.newSearchService(clusterService, indicesService, threadPool, scriptService, bigArrays, fetchPhase); } - return MockSearchService.class; + return new MockSearchService(clusterService, indicesService, threadPool, scriptService, bigArrays, fetchPhase); } } + diff --git a/test/framework/src/main/java/org/elasticsearch/search/MockSearchService.java b/test/framework/src/main/java/org/elasticsearch/search/MockSearchService.java index cae5b2ff95b..bf300889cd5 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/MockSearchService.java +++ b/test/framework/src/main/java/org/elasticsearch/search/MockSearchService.java @@ -20,9 +20,6 @@ package org.elasticsearch.search; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.ClusterSettings; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.node.MockNode; @@ -69,11 +66,10 @@ public class MockSearchService extends SearchService { ACTIVE_SEARCH_CONTEXTS.remove(context); } - @Inject - public MockSearchService(Settings settings, ClusterSettings clusterSettings, ClusterService clusterService, + public MockSearchService(ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase) { - super(settings, clusterSettings, clusterService, indicesService, threadPool, scriptService, bigArrays, fetchPhase); + super(clusterService, indicesService, threadPool, scriptService, bigArrays, fetchPhase); } @Override diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index 85045aa3f80..0560ec2a910 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -1045,12 +1045,7 @@ public abstract class AbstractQueryTestCase> scriptSettings.addAll(pluginsService.getPluginSettings()); scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED); SettingsModule settingsModule = new SettingsModule(nodeSettings, scriptSettings, pluginsService.getPluginSettingsFilter()); - searchModule = new SearchModule(nodeSettings, false, pluginsService.filterPlugins(SearchPlugin.class)) { - @Override - protected void configureSearch() { - // Skip me - } - }; + searchModule = new SearchModule(nodeSettings, false, pluginsService.filterPlugins(SearchPlugin.class)); IndicesModule indicesModule = new IndicesModule(pluginsService.filterPlugins(MapperPlugin.class)) { @Override public void configure() { diff --git a/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java b/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java index 5495fb166b3..813686f4a3a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java +++ b/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java @@ -117,7 +117,7 @@ public class TestSearchContext extends SearchContext { } @Override - public void preProcess() { + public void preProcess(boolean rewrite) { } @Override