Deguice SearchService and friends (#20423)
This change removes the guice dependency handling for SearchService and several related classes like SearchTransportController and SearchPhaseController. The latter two now have package private constructors and dependencies like FetchPhase are now created by calling their constructors explicitly. This also cleans up several users of the DefaultSearchContext and centralized it's creation inside SearchService.
This commit is contained in:
parent
7f92971f26
commit
686994ae2d
|
@ -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<ValidateQueryRequest, ValidateQueryResponse, ShardValidateQueryRequest, ShardValidateQueryResponse> {
|
||||
|
||||
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<Valid
|
|||
|
||||
@Override
|
||||
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
||||
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
||||
|
||||
boolean valid;
|
||||
String explanation = null;
|
||||
String error = null;
|
||||
Engine.Searcher searcher = indexShard.acquireSearcher("validate_query");
|
||||
|
||||
DefaultSearchContext searchContext = new DefaultSearchContext(0,
|
||||
new ShardSearchLocalRequest(request.types(), request.nowInMillis(), request.filteringAliases()), null, searcher,
|
||||
indexService, indexShard, scriptService, bigArrays, threadPool.estimatedTimeInMillisCounter(),
|
||||
parseFieldMatcher, SearchService.NO_TIMEOUT, fetchPhase);
|
||||
ShardSearchLocalRequest shardSearchLocalRequest = new ShardSearchLocalRequest(request.shardId(), request.types(),
|
||||
request.nowInMillis(), request.filteringAliases());
|
||||
SearchContext searchContext = searchService.createSearchContext(shardSearchLocalRequest, SearchService.NO_TIMEOUT, null);
|
||||
SearchContext.setCurrent(searchContext);
|
||||
try {
|
||||
searchContext.parsedQuery(searchContext.getQueryShardContext().toQuery(request.query()));
|
||||
searchContext.preProcess();
|
||||
|
||||
ParsedQuery parsedQuery = searchContext.getQueryShardContext().toQuery(request.query());
|
||||
searchContext.parsedQuery(parsedQuery);
|
||||
searchContext.preProcess(request.rewrite());
|
||||
valid = true;
|
||||
if (request.rewrite()) {
|
||||
explanation = getRewrittenQuery(searcher.searcher(), searchContext.query());
|
||||
} else if (request.explain()) {
|
||||
explanation = searchContext.filteredQuery().query().toString();
|
||||
}
|
||||
explanation = explain(searchContext, request.rewrite());
|
||||
} catch (QueryShardException|ParsingException e) {
|
||||
valid = false;
|
||||
error = e.getDetailedMessage();
|
||||
|
@ -191,19 +166,18 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
|
|||
valid = false;
|
||||
error = e.getMessage();
|
||||
} finally {
|
||||
searchContext.close();
|
||||
SearchContext.removeCurrent();
|
||||
Releasables.close(searchContext, () -> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ExplainRequest, ExplainResponse> {
|
||||
|
||||
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<ExplainRe
|
|||
|
||||
@Override
|
||||
protected ExplainResponse shardOperation(ExplainRequest request, ShardId shardId) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
ShardSearchLocalRequest shardSearchLocalRequest = new ShardSearchLocalRequest(shardId,
|
||||
new String[]{request.type()}, request.nowInMillis, request.filteringAlias());
|
||||
SearchContext context = searchService.createSearchContext(shardSearchLocalRequest, SearchService.NO_TIMEOUT, null);
|
||||
Term uidTerm = new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(request.type(), request.id()));
|
||||
Engine.GetResult result = indexShard.get(new Engine.Get(false, uidTerm));
|
||||
if (!result.exists()) {
|
||||
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), false);
|
||||
}
|
||||
|
||||
SearchContext context = new DefaultSearchContext(0,
|
||||
new ShardSearchLocalRequest(new String[] { request.type() }, request.nowInMillis, request.filteringAlias()), null,
|
||||
result.searcher(), indexService, indexShard, scriptService, bigArrays,
|
||||
threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, SearchService.NO_TIMEOUT, fetchPhase);
|
||||
SearchContext.setCurrent(context);
|
||||
|
||||
Engine.GetResult result = null;
|
||||
try {
|
||||
result = context.indexShard().get(new Engine.Get(false, uidTerm));
|
||||
if (!result.exists()) {
|
||||
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), false);
|
||||
}
|
||||
context.parsedQuery(context.getQueryShardContext().toQuery(request.query()));
|
||||
context.preProcess();
|
||||
context.preProcess(true);
|
||||
int topLevelDocId = result.docIdAndVersion().docId + result.docIdAndVersion().context.docBase;
|
||||
Explanation explanation = context.searcher().explain(context.query(), topLevelDocId);
|
||||
for (RescoreSearchContext ctx : context.rescore()) {
|
||||
|
@ -131,7 +110,8 @@ public class TransportExplainAction extends TransportSingleShardAction<ExplainRe
|
|||
// Advantage is that we're not opening a second searcher to retrieve the _source. Also
|
||||
// because we are working in the same searcher in engineGetResult we can be sure that a
|
||||
// doc isn't deleted between the initial get and this call.
|
||||
GetResult getResult = indexShard.getService().get(result, request.id(), request.type(), request.fields(), request.fetchSourceContext());
|
||||
GetResult getResult = context.indexShard().getService().get(result, request.id(), request.type(), request.fields(),
|
||||
request.fetchSourceContext());
|
||||
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), true, explanation, getResult);
|
||||
} else {
|
||||
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), true, explanation);
|
||||
|
@ -139,8 +119,7 @@ public class TransportExplainAction extends TransportSingleShardAction<ExplainRe
|
|||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("Could not explain", e);
|
||||
} finally {
|
||||
context.close();
|
||||
SearchContext.removeCurrent();
|
||||
Releasables.close(result, context, () -> SearchContext.removeCurrent());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,6 @@ public class GetRequest extends SingleShardRequest<GetRequest> 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<GetRequest> 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<GetRequest> 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<GetRequest> implements Realti
|
|||
}
|
||||
}
|
||||
out.writeBoolean(realtime);
|
||||
out.writeBoolean(ignoreErrorsOnGeneratedFields);
|
||||
out.writeByte(versionType.getValue());
|
||||
out.writeLong(version);
|
||||
out.writeOptionalStreamable(fetchSourceContext);
|
||||
|
|
|
@ -155,11 +155,6 @@ public class GetRequestBuilder extends SingleShardOperationRequestBuilder<GetReq
|
|||
return this;
|
||||
}
|
||||
|
||||
public GetRequestBuilder setIgnoreErrorsOnGeneratedFields(Boolean ignoreErrorsOnGeneratedFields) {
|
||||
request.ignoreErrorsOnGeneratedFields(ignoreErrorsOnGeneratedFields);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the version, which will cause the get operation to only be performed if a matching
|
||||
* version exists and no changes happened on the doc since then.
|
||||
|
|
|
@ -262,8 +262,6 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
|
|||
String preference;
|
||||
boolean realtime = true;
|
||||
boolean refresh;
|
||||
public boolean ignoreErrorsOnGeneratedFields = false;
|
||||
|
||||
List<Item> items = new ArrayList<>();
|
||||
|
||||
public List<Item> getItems() {
|
||||
|
@ -338,11 +336,6 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> 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<MultiGetRequest> 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<MultiGetRequest> implements I
|
|||
out.writeOptionalString(preference);
|
||||
out.writeBoolean(refresh);
|
||||
out.writeBoolean(realtime);
|
||||
out.writeBoolean(ignoreErrorsOnGeneratedFields);
|
||||
|
||||
out.writeVInt(items.size());
|
||||
for (Item item : items) {
|
||||
|
|
|
@ -80,9 +80,4 @@ public class MultiGetRequestBuilder extends ActionRequestBuilder<MultiGetRequest
|
|||
request.realtime(realtime);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiGetRequestBuilder setIgnoreErrorsOnGeneratedFields(boolean ignoreErrorsOnGeneratedFields) {
|
||||
request.ignoreErrorsOnGeneratedFields(ignoreErrorsOnGeneratedFields);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
|||
private String preference;
|
||||
boolean realtime = true;
|
||||
boolean refresh;
|
||||
boolean ignoreErrorsOnGeneratedFields = false;
|
||||
|
||||
IntArrayList locations;
|
||||
List<MultiGetRequest.Item> items;
|
||||
|
@ -52,7 +51,6 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
|||
preference = multiGetRequest.preference;
|
||||
realtime = multiGetRequest.realtime;
|
||||
refresh = multiGetRequest.refresh;
|
||||
ignoreErrorsOnGeneratedFields = multiGetRequest.ignoreErrorsOnGeneratedFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,11 +85,6 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
|||
return this;
|
||||
}
|
||||
|
||||
public MultiGetShardRequest ignoreErrorsOnGeneratedFields(Boolean ignoreErrorsOnGeneratedFields) {
|
||||
this.ignoreErrorsOnGeneratedFields = ignoreErrorsOnGeneratedFields;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean refresh() {
|
||||
return this.refresh;
|
||||
}
|
||||
|
@ -130,7 +123,6 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
|||
preference = in.readOptionalString();
|
||||
refresh = in.readBoolean();
|
||||
realtime = in.readBoolean();
|
||||
ignoreErrorsOnGeneratedFields = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -146,11 +138,5 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
|||
out.writeOptionalString(preference);
|
||||
out.writeBoolean(refresh);
|
||||
out.writeBoolean(realtime);
|
||||
out.writeBoolean(ignoreErrorsOnGeneratedFields);
|
||||
|
||||
}
|
||||
|
||||
public boolean ignoreErrorsOnGeneratedFields() {
|
||||
return ignoreErrorsOnGeneratedFields;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public class TransportGetAction extends TransportSingleShardAction<GetRequest, G
|
|||
}
|
||||
|
||||
GetResult result = indexShard.getService().get(request.type(), request.id(), request.fields(),
|
||||
request.realtime(), request.version(), request.versionType(), request.fetchSourceContext(), request.ignoreErrorsOnGeneratedFields());
|
||||
request.realtime(), request.version(), request.versionType(), request.fetchSourceContext());
|
||||
return new GetResponse(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,13 +88,15 @@ public class TransportShardMultiGetAction extends TransportSingleShardAction<Mul
|
|||
for (int i = 0; i < request.locations.size(); i++) {
|
||||
MultiGetRequest.Item item = request.items.get(i);
|
||||
try {
|
||||
GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.fields(), request.realtime(), item.version(), item.versionType(), item.fetchSourceContext(), request.ignoreErrorsOnGeneratedFields());
|
||||
GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.fields(), request.realtime(), item.version(),
|
||||
item.versionType(), item.fetchSourceContext());
|
||||
response.add(request.locations.get(i), new GetResponse(getResult));
|
||||
} catch (Exception e) {
|
||||
if (TransportActions.isShardNotAvailableException(e)) {
|
||||
throw (ElasticsearchException) e;
|
||||
} else {
|
||||
logger.debug((Supplier<?>) () -> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -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<ClearScro
|
|||
|
||||
@Inject
|
||||
public TransportClearScrollAction(Settings settings, TransportService transportService, ThreadPool threadPool,
|
||||
ClusterService clusterService, SearchTransportService searchTransportService,
|
||||
ClusterService clusterService, SearchService searchService,
|
||||
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||
super(settings, ClearScrollAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, ClearScrollRequest::new);
|
||||
this.clusterService = clusterService;
|
||||
this.searchTransportService = searchTransportService;
|
||||
this.searchTransportService = new SearchTransportService(settings, transportService, searchService);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,10 +29,11 @@ import org.elasticsearch.common.inject.Inject;
|
|||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Setting.Property;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.BigArrays;
|
||||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.indices.IndexClosedException;
|
||||
import org.elasticsearch.search.action.SearchTransportService;
|
||||
import org.elasticsearch.search.controller.SearchPhaseController;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.SearchService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
|
@ -53,13 +54,13 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|||
private final SearchPhaseController searchPhaseController;
|
||||
|
||||
@Inject
|
||||
public TransportSearchAction(Settings settings, ThreadPool threadPool, SearchPhaseController searchPhaseController,
|
||||
TransportService transportService, SearchTransportService searchTransportService,
|
||||
public TransportSearchAction(Settings settings, ThreadPool threadPool, BigArrays bigArrays, ScriptService scriptService,
|
||||
TransportService transportService, SearchService searchService,
|
||||
ClusterService clusterService, ActionFilters actionFilters, IndexNameExpressionResolver
|
||||
indexNameExpressionResolver) {
|
||||
super(settings, SearchAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, SearchRequest::new);
|
||||
this.searchPhaseController = searchPhaseController;
|
||||
this.searchTransportService = searchTransportService;
|
||||
this.searchPhaseController = new SearchPhaseController(settings, bigArrays, scriptService, clusterService);;
|
||||
this.searchTransportService = new SearchTransportService(settings, transportService, searchService);
|
||||
this.clusterService = clusterService;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,9 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.search.action.SearchTransportService;
|
||||
import org.elasticsearch.search.controller.SearchPhaseController;
|
||||
import org.elasticsearch.common.util.BigArrays;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.SearchService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
|
@ -45,15 +46,15 @@ public class TransportSearchScrollAction extends HandledTransportAction<SearchSc
|
|||
private final SearchPhaseController searchPhaseController;
|
||||
|
||||
@Inject
|
||||
public TransportSearchScrollAction(Settings settings, ThreadPool threadPool, TransportService transportService,
|
||||
ClusterService clusterService, SearchTransportService searchTransportService,
|
||||
SearchPhaseController searchPhaseController,
|
||||
public TransportSearchScrollAction(Settings settings, BigArrays bigArrays, ThreadPool threadPool, ScriptService scriptService,
|
||||
TransportService transportService,
|
||||
ClusterService clusterService, SearchService searchService,
|
||||
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||
super(settings, SearchScrollAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver,
|
||||
SearchScrollRequest::new);
|
||||
this.clusterService = clusterService;
|
||||
this.searchTransportService = searchTransportService;
|
||||
this.searchPhaseController = searchPhaseController;
|
||||
this.searchTransportService = new SearchTransportService(settings, transportService, searchService);
|
||||
this.searchPhaseController = new SearchPhaseController(settings, bigArrays, scriptService, clusterService);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,7 +76,7 @@ public class UpdateHelper extends AbstractComponent {
|
|||
public Result prepare(UpdateRequest request, IndexShard indexShard) {
|
||||
final GetResult getResult = indexShard.getService().get(request.type(), request.id(),
|
||||
new String[]{RoutingFieldMapper.NAME, ParentFieldMapper.NAME, TTLFieldMapper.NAME, TimestampFieldMapper.NAME},
|
||||
true, request.version(), request.versionType(), FetchSourceContext.FETCH_SOURCE, false);
|
||||
true, request.version(), request.versionType(), FetchSourceContext.FETCH_SOURCE);
|
||||
return prepare(indexShard.shardId(), request, getResult);
|
||||
}
|
||||
|
||||
|
|
|
@ -76,11 +76,11 @@ public final class ShardGetService extends AbstractIndexShardComponent {
|
|||
return new GetStats(existsMetric.count(), TimeUnit.NANOSECONDS.toMillis(existsMetric.sum()), missingMetric.count(), TimeUnit.NANOSECONDS.toMillis(missingMetric.sum()), currentMetric.count());
|
||||
}
|
||||
|
||||
public GetResult get(String type, String id, String[] gFields, boolean realtime, long version, VersionType versionType, FetchSourceContext fetchSourceContext, boolean ignoreErrorsOnGeneratedFields) {
|
||||
public GetResult get(String type, String id, String[] gFields, boolean realtime, long version, VersionType versionType, FetchSourceContext fetchSourceContext) {
|
||||
currentMetric.inc();
|
||||
try {
|
||||
long now = System.nanoTime();
|
||||
GetResult getResult = innerGet(type, id, gFields, realtime, version, versionType, fetchSourceContext, ignoreErrorsOnGeneratedFields);
|
||||
GetResult getResult = innerGet(type, id, gFields, realtime, version, versionType, fetchSourceContext);
|
||||
|
||||
if (getResult.isExists()) {
|
||||
existsMetric.inc(System.nanoTime() - now);
|
||||
|
@ -139,7 +139,7 @@ public final class ShardGetService extends AbstractIndexShardComponent {
|
|||
return FetchSourceContext.DO_NOT_FETCH_SOURCE;
|
||||
}
|
||||
|
||||
private GetResult innerGet(String type, String id, String[] gFields, boolean realtime, long version, VersionType versionType, FetchSourceContext fetchSourceContext, boolean ignoreErrorsOnGeneratedFields) {
|
||||
private GetResult innerGet(String type, String id, String[] gFields, boolean realtime, long version, VersionType versionType, FetchSourceContext fetchSourceContext) {
|
||||
fetchSourceContext = normalizeFetchSourceContent(fetchSourceContext, gFields);
|
||||
|
||||
Engine.GetResult get = null;
|
||||
|
|
|
@ -113,6 +113,7 @@ import org.elasticsearch.script.ScriptModule;
|
|||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.SearchModule;
|
||||
import org.elasticsearch.search.SearchService;
|
||||
import org.elasticsearch.search.fetch.FetchPhase;
|
||||
import org.elasticsearch.snapshots.SnapshotShardsService;
|
||||
import org.elasticsearch.snapshots.SnapshotsService;
|
||||
import org.elasticsearch.tasks.TaskResultsService;
|
||||
|
@ -122,7 +123,6 @@ import org.elasticsearch.transport.TransportService;
|
|||
import org.elasticsearch.tribe.TribeService;
|
||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||
|
||||
import javax.management.MBeanServerPermission;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
@ -133,13 +133,11 @@ import java.nio.charset.Charset;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.security.AccessControlException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -383,12 +381,8 @@ public class Node implements Closeable {
|
|||
b.bind(MetaDataUpgrader.class).toInstance(metaDataUpgrader);
|
||||
b.bind(MetaStateService.class).toInstance(metaStateService);
|
||||
b.bind(IndicesService.class).toInstance(indicesService);
|
||||
Class<? extends SearchService> 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<? extends SearchService> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -77,7 +77,7 @@ public class SubSearchContext extends FilteredSearchContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void preProcess() {
|
||||
public void preProcess(boolean rewrite) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -85,7 +85,7 @@ public class QueryPhase implements SearchPhase {
|
|||
|
||||
@Override
|
||||
public void preProcess(SearchContext context) {
|
||||
context.preProcess();
|
||||
context.preProcess(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
|
@ -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<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||
entries.addAll(indicesModule.getNamedWriteables());
|
||||
entries.addAll(searchModule.getNamedWriteables());
|
||||
|
|
|
@ -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<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||
entries.addAll(indicesModule.getNamedWriteables());
|
||||
entries.addAll(searchModule.getNamedWriteables());
|
||||
|
|
|
@ -143,12 +143,7 @@ public abstract class BaseAggregationTestCase<AB extends AbstractAggregationBuil
|
|||
bindMapperExtension();
|
||||
}
|
||||
};
|
||||
SearchModule searchModule = new SearchModule(settings, false, emptyList()) {
|
||||
@Override
|
||||
protected void configureSearch() {
|
||||
// Skip me
|
||||
}
|
||||
};
|
||||
SearchModule searchModule = new SearchModule(settings, false, emptyList());
|
||||
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||
entries.addAll(indicesModule.getNamedWriteables());
|
||||
entries.addAll(searchModule.getNamedWriteables());
|
||||
|
|
|
@ -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<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||
entries.addAll(indicesModule.getNamedWriteables());
|
||||
entries.addAll(searchModule.getNamedWriteables());
|
||||
|
|
|
@ -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<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||
entries.addAll(indicesModule.getNamedWriteables());
|
||||
entries.addAll(searchModule.getNamedWriteables());
|
||||
|
|
|
@ -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<? extends SearchService> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1045,12 +1045,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
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() {
|
||||
|
|
|
@ -117,7 +117,7 @@ public class TestSearchContext extends SearchContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void preProcess() {
|
||||
public void preProcess(boolean rewrite) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue