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.ParsingException;
|
||||||
import org.elasticsearch.common.Randomness;
|
import org.elasticsearch.common.Randomness;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
import org.elasticsearch.common.lease.Releasables;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.BigArrays;
|
import org.elasticsearch.index.query.ParsedQuery;
|
||||||
import org.elasticsearch.index.IndexService;
|
|
||||||
import org.elasticsearch.index.engine.Engine;
|
|
||||||
import org.elasticsearch.index.query.QueryShardException;
|
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.SearchService;
|
||||||
import org.elasticsearch.search.fetch.FetchPhase;
|
|
||||||
import org.elasticsearch.search.internal.DefaultSearchContext;
|
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
import org.elasticsearch.search.internal.ShardSearchLocalRequest;
|
import org.elasticsearch.search.internal.ShardSearchLocalRequest;
|
||||||
import org.elasticsearch.tasks.Task;
|
import org.elasticsearch.tasks.Task;
|
||||||
|
@ -67,25 +61,15 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||||
*/
|
*/
|
||||||
public class TransportValidateQueryAction extends TransportBroadcastAction<ValidateQueryRequest, ValidateQueryResponse, ShardValidateQueryRequest, ShardValidateQueryResponse> {
|
public class TransportValidateQueryAction extends TransportBroadcastAction<ValidateQueryRequest, ValidateQueryResponse, ShardValidateQueryRequest, ShardValidateQueryResponse> {
|
||||||
|
|
||||||
private final IndicesService indicesService;
|
private final SearchService searchService;
|
||||||
|
|
||||||
private final ScriptService scriptService;
|
|
||||||
|
|
||||||
private final BigArrays bigArrays;
|
|
||||||
|
|
||||||
private final FetchPhase fetchPhase;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportValidateQueryAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
|
public TransportValidateQueryAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
|
||||||
TransportService transportService, IndicesService indicesService, ScriptService scriptService,
|
TransportService transportService, SearchService searchService, ActionFilters actionFilters,
|
||||||
BigArrays bigArrays, ActionFilters actionFilters,
|
IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||||
IndexNameExpressionResolver indexNameExpressionResolver, FetchPhase fetchPhase) {
|
|
||||||
super(settings, ValidateQueryAction.NAME, threadPool, clusterService, transportService, actionFilters,
|
super(settings, ValidateQueryAction.NAME, threadPool, clusterService, transportService, actionFilters,
|
||||||
indexNameExpressionResolver, ValidateQueryRequest::new, ShardValidateQueryRequest::new, ThreadPool.Names.SEARCH);
|
indexNameExpressionResolver, ValidateQueryRequest::new, ShardValidateQueryRequest::new, ThreadPool.Names.SEARCH);
|
||||||
this.indicesService = indicesService;
|
this.searchService = searchService;
|
||||||
this.scriptService = scriptService;
|
|
||||||
this.bigArrays = bigArrays;
|
|
||||||
this.fetchPhase = fetchPhase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -161,29 +145,20 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) {
|
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) {
|
||||||
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
|
|
||||||
IndexShard indexShard = indexService.getShard(request.shardId().id());
|
|
||||||
|
|
||||||
boolean valid;
|
boolean valid;
|
||||||
String explanation = null;
|
String explanation = null;
|
||||||
String error = null;
|
String error = null;
|
||||||
Engine.Searcher searcher = indexShard.acquireSearcher("validate_query");
|
ShardSearchLocalRequest shardSearchLocalRequest = new ShardSearchLocalRequest(request.shardId(), request.types(),
|
||||||
|
request.nowInMillis(), request.filteringAliases());
|
||||||
DefaultSearchContext searchContext = new DefaultSearchContext(0,
|
SearchContext searchContext = searchService.createSearchContext(shardSearchLocalRequest, SearchService.NO_TIMEOUT, null);
|
||||||
new ShardSearchLocalRequest(request.types(), request.nowInMillis(), request.filteringAliases()), null, searcher,
|
|
||||||
indexService, indexShard, scriptService, bigArrays, threadPool.estimatedTimeInMillisCounter(),
|
|
||||||
parseFieldMatcher, SearchService.NO_TIMEOUT, fetchPhase);
|
|
||||||
SearchContext.setCurrent(searchContext);
|
SearchContext.setCurrent(searchContext);
|
||||||
try {
|
try {
|
||||||
searchContext.parsedQuery(searchContext.getQueryShardContext().toQuery(request.query()));
|
ParsedQuery parsedQuery = searchContext.getQueryShardContext().toQuery(request.query());
|
||||||
searchContext.preProcess();
|
searchContext.parsedQuery(parsedQuery);
|
||||||
|
searchContext.preProcess(request.rewrite());
|
||||||
valid = true;
|
valid = true;
|
||||||
if (request.rewrite()) {
|
explanation = explain(searchContext, request.rewrite());
|
||||||
explanation = getRewrittenQuery(searcher.searcher(), searchContext.query());
|
|
||||||
} else if (request.explain()) {
|
|
||||||
explanation = searchContext.filteredQuery().query().toString();
|
|
||||||
}
|
|
||||||
} catch (QueryShardException|ParsingException e) {
|
} catch (QueryShardException|ParsingException e) {
|
||||||
valid = false;
|
valid = false;
|
||||||
error = e.getDetailedMessage();
|
error = e.getDetailedMessage();
|
||||||
|
@ -191,19 +166,18 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
|
||||||
valid = false;
|
valid = false;
|
||||||
error = e.getMessage();
|
error = e.getMessage();
|
||||||
} finally {
|
} finally {
|
||||||
searchContext.close();
|
Releasables.close(searchContext, () -> SearchContext.removeCurrent());
|
||||||
SearchContext.removeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ShardValidateQueryResponse(request.shardId(), valid, explanation, error);
|
return new ShardValidateQueryResponse(request.shardId(), valid, explanation, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRewrittenQuery(IndexSearcher searcher, Query query) throws IOException {
|
private String explain(SearchContext context, boolean rewritten) throws IOException {
|
||||||
Query queryRewrite = searcher.rewrite(query);
|
Query query = context.query();
|
||||||
if (queryRewrite instanceof MatchNoDocsQuery) {
|
if (rewritten && query instanceof MatchNoDocsQuery) {
|
||||||
return query.toString();
|
return context.parsedQuery().query().toString();
|
||||||
} else {
|
} 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.routing.ShardIterator;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
import org.elasticsearch.common.lease.Releasables;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
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.engine.Engine;
|
||||||
import org.elasticsearch.index.get.GetResult;
|
import org.elasticsearch.index.get.GetResult;
|
||||||
import org.elasticsearch.index.mapper.Uid;
|
import org.elasticsearch.index.mapper.Uid;
|
||||||
import org.elasticsearch.index.mapper.UidFieldMapper;
|
import org.elasticsearch.index.mapper.UidFieldMapper;
|
||||||
import org.elasticsearch.index.shard.IndexShard;
|
|
||||||
import org.elasticsearch.index.shard.ShardId;
|
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.SearchService;
|
||||||
import org.elasticsearch.search.fetch.FetchPhase;
|
|
||||||
import org.elasticsearch.search.internal.DefaultSearchContext;
|
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
import org.elasticsearch.search.internal.ShardSearchLocalRequest;
|
import org.elasticsearch.search.internal.ShardSearchLocalRequest;
|
||||||
import org.elasticsearch.search.rescore.RescoreSearchContext;
|
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.
|
// TODO: AggregatedDfs. Currently the idf can be different then when executing a normal search with explain.
|
||||||
public class TransportExplainAction extends TransportSingleShardAction<ExplainRequest, ExplainResponse> {
|
public class TransportExplainAction extends TransportSingleShardAction<ExplainRequest, ExplainResponse> {
|
||||||
|
|
||||||
private final IndicesService indicesService;
|
private final SearchService searchService;
|
||||||
|
|
||||||
private final ScriptService scriptService;
|
|
||||||
|
|
||||||
|
|
||||||
private final BigArrays bigArrays;
|
|
||||||
|
|
||||||
private final FetchPhase fetchPhase;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportExplainAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
|
public TransportExplainAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
|
||||||
TransportService transportService, IndicesService indicesService, ScriptService scriptService,
|
TransportService transportService, SearchService searchService, ActionFilters actionFilters,
|
||||||
BigArrays bigArrays, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
|
IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||||
FetchPhase fetchPhase) {
|
|
||||||
super(settings, ExplainAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver,
|
super(settings, ExplainAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver,
|
||||||
ExplainRequest::new, ThreadPool.Names.GET);
|
ExplainRequest::new, ThreadPool.Names.GET);
|
||||||
this.indicesService = indicesService;
|
this.searchService = searchService;
|
||||||
this.scriptService = scriptService;
|
|
||||||
this.bigArrays = bigArrays;
|
|
||||||
this.fetchPhase = fetchPhase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,23 +87,19 @@ public class TransportExplainAction extends TransportSingleShardAction<ExplainRe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ExplainResponse shardOperation(ExplainRequest request, ShardId shardId) {
|
protected ExplainResponse shardOperation(ExplainRequest request, ShardId shardId) {
|
||||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
ShardSearchLocalRequest shardSearchLocalRequest = new ShardSearchLocalRequest(shardId,
|
||||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
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()));
|
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);
|
SearchContext.setCurrent(context);
|
||||||
|
Engine.GetResult result = null;
|
||||||
try {
|
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.parsedQuery(context.getQueryShardContext().toQuery(request.query()));
|
||||||
context.preProcess();
|
context.preProcess(true);
|
||||||
int topLevelDocId = result.docIdAndVersion().docId + result.docIdAndVersion().context.docBase;
|
int topLevelDocId = result.docIdAndVersion().docId + result.docIdAndVersion().context.docBase;
|
||||||
Explanation explanation = context.searcher().explain(context.query(), topLevelDocId);
|
Explanation explanation = context.searcher().explain(context.query(), topLevelDocId);
|
||||||
for (RescoreSearchContext ctx : context.rescore()) {
|
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
|
// 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
|
// 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.
|
// 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);
|
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), true, explanation, getResult);
|
||||||
} else {
|
} else {
|
||||||
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), true, explanation);
|
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), true, explanation);
|
||||||
|
@ -139,8 +119,7 @@ public class TransportExplainAction extends TransportSingleShardAction<ExplainRe
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ElasticsearchException("Could not explain", e);
|
throw new ElasticsearchException("Could not explain", e);
|
||||||
} finally {
|
} finally {
|
||||||
context.close();
|
Releasables.close(result, context, () -> SearchContext.removeCurrent());
|
||||||
SearchContext.removeCurrent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,6 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
|
||||||
|
|
||||||
private VersionType versionType = VersionType.INTERNAL;
|
private VersionType versionType = VersionType.INTERNAL;
|
||||||
private long version = Versions.MATCH_ANY;
|
private long version = Versions.MATCH_ANY;
|
||||||
private boolean ignoreErrorsOnGeneratedFields;
|
|
||||||
|
|
||||||
public GetRequest() {
|
public GetRequest() {
|
||||||
type = "_all";
|
type = "_all";
|
||||||
|
@ -248,19 +247,10 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetRequest ignoreErrorsOnGeneratedFields(boolean ignoreErrorsOnGeneratedFields) {
|
|
||||||
this.ignoreErrorsOnGeneratedFields = ignoreErrorsOnGeneratedFields;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VersionType versionType() {
|
public VersionType versionType() {
|
||||||
return this.versionType;
|
return this.versionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ignoreErrorsOnGeneratedFields() {
|
|
||||||
return ignoreErrorsOnGeneratedFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
|
@ -278,7 +268,6 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
realtime = in.readBoolean();
|
realtime = in.readBoolean();
|
||||||
this.ignoreErrorsOnGeneratedFields = in.readBoolean();
|
|
||||||
|
|
||||||
this.versionType = VersionType.fromValue(in.readByte());
|
this.versionType = VersionType.fromValue(in.readByte());
|
||||||
this.version = in.readLong();
|
this.version = in.readLong();
|
||||||
|
@ -304,7 +293,6 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.writeBoolean(realtime);
|
out.writeBoolean(realtime);
|
||||||
out.writeBoolean(ignoreErrorsOnGeneratedFields);
|
|
||||||
out.writeByte(versionType.getValue());
|
out.writeByte(versionType.getValue());
|
||||||
out.writeLong(version);
|
out.writeLong(version);
|
||||||
out.writeOptionalStreamable(fetchSourceContext);
|
out.writeOptionalStreamable(fetchSourceContext);
|
||||||
|
|
|
@ -155,11 +155,6 @@ public class GetRequestBuilder extends SingleShardOperationRequestBuilder<GetReq
|
||||||
return this;
|
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
|
* 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.
|
* 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;
|
String preference;
|
||||||
boolean realtime = true;
|
boolean realtime = true;
|
||||||
boolean refresh;
|
boolean refresh;
|
||||||
public boolean ignoreErrorsOnGeneratedFields = false;
|
|
||||||
|
|
||||||
List<Item> items = new ArrayList<>();
|
List<Item> items = new ArrayList<>();
|
||||||
|
|
||||||
public List<Item> getItems() {
|
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 {
|
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);
|
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();
|
preference = in.readOptionalString();
|
||||||
refresh = in.readBoolean();
|
refresh = in.readBoolean();
|
||||||
realtime = in.readBoolean();
|
realtime = in.readBoolean();
|
||||||
ignoreErrorsOnGeneratedFields = in.readBoolean();
|
|
||||||
|
|
||||||
int size = in.readVInt();
|
int size = in.readVInt();
|
||||||
items = new ArrayList<>(size);
|
items = new ArrayList<>(size);
|
||||||
|
@ -525,7 +517,6 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
|
||||||
out.writeOptionalString(preference);
|
out.writeOptionalString(preference);
|
||||||
out.writeBoolean(refresh);
|
out.writeBoolean(refresh);
|
||||||
out.writeBoolean(realtime);
|
out.writeBoolean(realtime);
|
||||||
out.writeBoolean(ignoreErrorsOnGeneratedFields);
|
|
||||||
|
|
||||||
out.writeVInt(items.size());
|
out.writeVInt(items.size());
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
|
|
|
@ -80,9 +80,4 @@ public class MultiGetRequestBuilder extends ActionRequestBuilder<MultiGetRequest
|
||||||
request.realtime(realtime);
|
request.realtime(realtime);
|
||||||
return this;
|
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;
|
private String preference;
|
||||||
boolean realtime = true;
|
boolean realtime = true;
|
||||||
boolean refresh;
|
boolean refresh;
|
||||||
boolean ignoreErrorsOnGeneratedFields = false;
|
|
||||||
|
|
||||||
IntArrayList locations;
|
IntArrayList locations;
|
||||||
List<MultiGetRequest.Item> items;
|
List<MultiGetRequest.Item> items;
|
||||||
|
@ -52,7 +51,6 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
||||||
preference = multiGetRequest.preference;
|
preference = multiGetRequest.preference;
|
||||||
realtime = multiGetRequest.realtime;
|
realtime = multiGetRequest.realtime;
|
||||||
refresh = multiGetRequest.refresh;
|
refresh = multiGetRequest.refresh;
|
||||||
ignoreErrorsOnGeneratedFields = multiGetRequest.ignoreErrorsOnGeneratedFields;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,11 +85,6 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiGetShardRequest ignoreErrorsOnGeneratedFields(Boolean ignoreErrorsOnGeneratedFields) {
|
|
||||||
this.ignoreErrorsOnGeneratedFields = ignoreErrorsOnGeneratedFields;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean refresh() {
|
public boolean refresh() {
|
||||||
return this.refresh;
|
return this.refresh;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +123,6 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
||||||
preference = in.readOptionalString();
|
preference = in.readOptionalString();
|
||||||
refresh = in.readBoolean();
|
refresh = in.readBoolean();
|
||||||
realtime = in.readBoolean();
|
realtime = in.readBoolean();
|
||||||
ignoreErrorsOnGeneratedFields = in.readBoolean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -146,11 +138,5 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
||||||
out.writeOptionalString(preference);
|
out.writeOptionalString(preference);
|
||||||
out.writeBoolean(refresh);
|
out.writeBoolean(refresh);
|
||||||
out.writeBoolean(realtime);
|
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(),
|
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);
|
return new GetResponse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,13 +88,15 @@ public class TransportShardMultiGetAction extends TransportSingleShardAction<Mul
|
||||||
for (int i = 0; i < request.locations.size(); i++) {
|
for (int i = 0; i < request.locations.size(); i++) {
|
||||||
MultiGetRequest.Item item = request.items.get(i);
|
MultiGetRequest.Item item = request.items.get(i);
|
||||||
try {
|
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));
|
response.add(request.locations.get(i), new GetResponse(getResult));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (TransportActions.isShardNotAvailableException(e)) {
|
if (TransportActions.isShardNotAvailableException(e)) {
|
||||||
throw (ElasticsearchException) e;
|
throw (ElasticsearchException) e;
|
||||||
} else {
|
} 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));
|
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.common.util.concurrent.AtomicArray;
|
||||||
import org.elasticsearch.search.SearchPhaseResult;
|
import org.elasticsearch.search.SearchPhaseResult;
|
||||||
import org.elasticsearch.search.SearchShardTarget;
|
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.fetch.ShardFetchSearchRequest;
|
||||||
import org.elasticsearch.search.internal.InternalSearchResponse;
|
import org.elasticsearch.search.internal.InternalSearchResponse;
|
||||||
import org.elasticsearch.search.internal.ShardSearchTransportRequest;
|
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.node.DiscoveryNode;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.util.concurrent.AtomicArray;
|
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.AggregatedDfs;
|
||||||
import org.elasticsearch.search.dfs.DfsSearchResult;
|
import org.elasticsearch.search.dfs.DfsSearchResult;
|
||||||
import org.elasticsearch.search.fetch.QueryFetchSearchResult;
|
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.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.util.concurrent.AtomicArray;
|
import org.elasticsearch.common.util.concurrent.AtomicArray;
|
||||||
import org.elasticsearch.search.SearchShardTarget;
|
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.AggregatedDfs;
|
||||||
import org.elasticsearch.search.dfs.DfsSearchResult;
|
import org.elasticsearch.search.dfs.DfsSearchResult;
|
||||||
import org.elasticsearch.search.fetch.FetchSearchResult;
|
import org.elasticsearch.search.fetch.FetchSearchResult;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.search.controller;
|
package org.elasticsearch.action.search;
|
||||||
|
|
||||||
import com.carrotsearch.hppc.IntArrayList;
|
import com.carrotsearch.hppc.IntArrayList;
|
||||||
import com.carrotsearch.hppc.ObjectObjectHashMap;
|
import com.carrotsearch.hppc.ObjectObjectHashMap;
|
||||||
|
@ -89,8 +89,7 @@ public class SearchPhaseController extends AbstractComponent {
|
||||||
private final ScriptService scriptService;
|
private final ScriptService scriptService;
|
||||||
private final ClusterService clusterService;
|
private final ClusterService clusterService;
|
||||||
|
|
||||||
@Inject
|
SearchPhaseController(Settings settings, BigArrays bigArrays, ScriptService scriptService, ClusterService clusterService) {
|
||||||
public SearchPhaseController(Settings settings, BigArrays bigArrays, ScriptService scriptService, ClusterService clusterService) {
|
|
||||||
super(settings);
|
super(settings);
|
||||||
this.bigArrays = bigArrays;
|
this.bigArrays = bigArrays;
|
||||||
this.scriptService = scriptService;
|
this.scriptService = scriptService;
|
|
@ -25,8 +25,6 @@ import org.elasticsearch.action.ActionRunnable;
|
||||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
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.fetch.QueryFetchSearchResult;
|
||||||
import org.elasticsearch.search.internal.InternalSearchResponse;
|
import org.elasticsearch.search.internal.InternalSearchResponse;
|
||||||
import org.elasticsearch.search.internal.ShardSearchTransportRequest;
|
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.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.util.concurrent.AtomicArray;
|
import org.elasticsearch.common.util.concurrent.AtomicArray;
|
||||||
import org.elasticsearch.search.SearchShardTarget;
|
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.FetchSearchResult;
|
||||||
import org.elasticsearch.search.fetch.ShardFetchSearchRequest;
|
import org.elasticsearch.search.fetch.ShardFetchSearchRequest;
|
||||||
import org.elasticsearch.search.internal.InternalSearchResponse;
|
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.node.DiscoveryNodes;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.util.concurrent.AtomicArray;
|
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.QueryFetchSearchResult;
|
||||||
import org.elasticsearch.search.fetch.ScrollQueryFetchSearchResult;
|
import org.elasticsearch.search.fetch.ScrollQueryFetchSearchResult;
|
||||||
import org.elasticsearch.search.internal.InternalScrollSearchRequest;
|
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.node.DiscoveryNodes;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.util.concurrent.AtomicArray;
|
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.FetchSearchResult;
|
||||||
import org.elasticsearch.search.fetch.ShardFetchRequest;
|
import org.elasticsearch.search.fetch.ShardFetchRequest;
|
||||||
import org.elasticsearch.search.internal.InternalScrollSearchRequest;
|
import org.elasticsearch.search.internal.InternalScrollSearchRequest;
|
||||||
|
|
|
@ -17,17 +17,15 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.search.action;
|
package org.elasticsearch.action.search;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.ActionListenerResponseHandler;
|
import org.elasticsearch.action.ActionListenerResponseHandler;
|
||||||
import org.elasticsearch.action.IndicesRequest;
|
import org.elasticsearch.action.IndicesRequest;
|
||||||
import org.elasticsearch.action.OriginalIndices;
|
import org.elasticsearch.action.OriginalIndices;
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
|
||||||
import org.elasticsearch.action.support.IndicesOptions;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.common.component.AbstractComponent;
|
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.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
@ -75,8 +73,7 @@ public class SearchTransportService extends AbstractComponent {
|
||||||
private final TransportService transportService;
|
private final TransportService transportService;
|
||||||
private final SearchService searchService;
|
private final SearchService searchService;
|
||||||
|
|
||||||
@Inject
|
SearchTransportService(Settings settings, TransportService transportService, SearchService searchService) {
|
||||||
public SearchTransportService(Settings settings, TransportService transportService, SearchService searchService) {
|
|
||||||
super(settings);
|
super(settings);
|
||||||
this.transportService = transportService;
|
this.transportService = transportService;
|
||||||
this.searchService = searchService;
|
this.searchService = searchService;
|
|
@ -32,7 +32,7 @@ import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.concurrent.CountDown;
|
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.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportResponse;
|
import org.elasticsearch.transport.TransportResponse;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
@ -53,11 +53,11 @@ public class TransportClearScrollAction extends HandledTransportAction<ClearScro
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportClearScrollAction(Settings settings, TransportService transportService, ThreadPool threadPool,
|
public TransportClearScrollAction(Settings settings, TransportService transportService, ThreadPool threadPool,
|
||||||
ClusterService clusterService, SearchTransportService searchTransportService,
|
ClusterService clusterService, SearchService searchService,
|
||||||
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||||
super(settings, ClearScrollAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, ClearScrollRequest::new);
|
super(settings, ClearScrollAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, ClearScrollRequest::new);
|
||||||
this.clusterService = clusterService;
|
this.clusterService = clusterService;
|
||||||
this.searchTransportService = searchTransportService;
|
this.searchTransportService = new SearchTransportService(settings, transportService, searchService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,10 +29,11 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
import org.elasticsearch.common.settings.Setting.Property;
|
import org.elasticsearch.common.settings.Setting.Property;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.util.BigArrays;
|
||||||
import org.elasticsearch.index.IndexNotFoundException;
|
import org.elasticsearch.index.IndexNotFoundException;
|
||||||
import org.elasticsearch.indices.IndexClosedException;
|
import org.elasticsearch.indices.IndexClosedException;
|
||||||
import org.elasticsearch.search.action.SearchTransportService;
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.search.controller.SearchPhaseController;
|
import org.elasticsearch.search.SearchService;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
|
||||||
|
@ -53,13 +54,13 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
||||||
private final SearchPhaseController searchPhaseController;
|
private final SearchPhaseController searchPhaseController;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportSearchAction(Settings settings, ThreadPool threadPool, SearchPhaseController searchPhaseController,
|
public TransportSearchAction(Settings settings, ThreadPool threadPool, BigArrays bigArrays, ScriptService scriptService,
|
||||||
TransportService transportService, SearchTransportService searchTransportService,
|
TransportService transportService, SearchService searchService,
|
||||||
ClusterService clusterService, ActionFilters actionFilters, IndexNameExpressionResolver
|
ClusterService clusterService, ActionFilters actionFilters, IndexNameExpressionResolver
|
||||||
indexNameExpressionResolver) {
|
indexNameExpressionResolver) {
|
||||||
super(settings, SearchAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, SearchRequest::new);
|
super(settings, SearchAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, SearchRequest::new);
|
||||||
this.searchPhaseController = searchPhaseController;
|
this.searchPhaseController = new SearchPhaseController(settings, bigArrays, scriptService, clusterService);;
|
||||||
this.searchTransportService = searchTransportService;
|
this.searchTransportService = new SearchTransportService(settings, transportService, searchService);
|
||||||
this.clusterService = clusterService;
|
this.clusterService = clusterService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,9 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.search.action.SearchTransportService;
|
import org.elasticsearch.common.util.BigArrays;
|
||||||
import org.elasticsearch.search.controller.SearchPhaseController;
|
import org.elasticsearch.script.ScriptService;
|
||||||
|
import org.elasticsearch.search.SearchService;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
|
||||||
|
@ -45,15 +46,15 @@ public class TransportSearchScrollAction extends HandledTransportAction<SearchSc
|
||||||
private final SearchPhaseController searchPhaseController;
|
private final SearchPhaseController searchPhaseController;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportSearchScrollAction(Settings settings, ThreadPool threadPool, TransportService transportService,
|
public TransportSearchScrollAction(Settings settings, BigArrays bigArrays, ThreadPool threadPool, ScriptService scriptService,
|
||||||
ClusterService clusterService, SearchTransportService searchTransportService,
|
TransportService transportService,
|
||||||
SearchPhaseController searchPhaseController,
|
ClusterService clusterService, SearchService searchService,
|
||||||
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||||
super(settings, SearchScrollAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver,
|
super(settings, SearchScrollAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver,
|
||||||
SearchScrollRequest::new);
|
SearchScrollRequest::new);
|
||||||
this.clusterService = clusterService;
|
this.clusterService = clusterService;
|
||||||
this.searchTransportService = searchTransportService;
|
this.searchTransportService = new SearchTransportService(settings, transportService, searchService);
|
||||||
this.searchPhaseController = searchPhaseController;
|
this.searchPhaseController = new SearchPhaseController(settings, bigArrays, scriptService, clusterService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class UpdateHelper extends AbstractComponent {
|
||||||
public Result prepare(UpdateRequest request, IndexShard indexShard) {
|
public Result prepare(UpdateRequest request, IndexShard indexShard) {
|
||||||
final GetResult getResult = indexShard.getService().get(request.type(), request.id(),
|
final GetResult getResult = indexShard.getService().get(request.type(), request.id(),
|
||||||
new String[]{RoutingFieldMapper.NAME, ParentFieldMapper.NAME, TTLFieldMapper.NAME, TimestampFieldMapper.NAME},
|
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);
|
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());
|
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();
|
currentMetric.inc();
|
||||||
try {
|
try {
|
||||||
long now = System.nanoTime();
|
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()) {
|
if (getResult.isExists()) {
|
||||||
existsMetric.inc(System.nanoTime() - now);
|
existsMetric.inc(System.nanoTime() - now);
|
||||||
|
@ -139,7 +139,7 @@ public final class ShardGetService extends AbstractIndexShardComponent {
|
||||||
return FetchSourceContext.DO_NOT_FETCH_SOURCE;
|
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);
|
fetchSourceContext = normalizeFetchSourceContent(fetchSourceContext, gFields);
|
||||||
|
|
||||||
Engine.GetResult get = null;
|
Engine.GetResult get = null;
|
||||||
|
|
|
@ -113,6 +113,7 @@ import org.elasticsearch.script.ScriptModule;
|
||||||
import org.elasticsearch.script.ScriptService;
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.search.SearchModule;
|
import org.elasticsearch.search.SearchModule;
|
||||||
import org.elasticsearch.search.SearchService;
|
import org.elasticsearch.search.SearchService;
|
||||||
|
import org.elasticsearch.search.fetch.FetchPhase;
|
||||||
import org.elasticsearch.snapshots.SnapshotShardsService;
|
import org.elasticsearch.snapshots.SnapshotShardsService;
|
||||||
import org.elasticsearch.snapshots.SnapshotsService;
|
import org.elasticsearch.snapshots.SnapshotsService;
|
||||||
import org.elasticsearch.tasks.TaskResultsService;
|
import org.elasticsearch.tasks.TaskResultsService;
|
||||||
|
@ -122,7 +123,6 @@ import org.elasticsearch.transport.TransportService;
|
||||||
import org.elasticsearch.tribe.TribeService;
|
import org.elasticsearch.tribe.TribeService;
|
||||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||||
|
|
||||||
import javax.management.MBeanServerPermission;
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -133,13 +133,11 @@ import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.security.AccessControlException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -383,12 +381,8 @@ public class Node implements Closeable {
|
||||||
b.bind(MetaDataUpgrader.class).toInstance(metaDataUpgrader);
|
b.bind(MetaDataUpgrader.class).toInstance(metaDataUpgrader);
|
||||||
b.bind(MetaStateService.class).toInstance(metaStateService);
|
b.bind(MetaStateService.class).toInstance(metaStateService);
|
||||||
b.bind(IndicesService.class).toInstance(indicesService);
|
b.bind(IndicesService.class).toInstance(indicesService);
|
||||||
Class<? extends SearchService> searchServiceImpl = pickSearchServiceImplementation();
|
b.bind(SearchService.class).toInstance(newSearchService(clusterService, indicesService,
|
||||||
if (searchServiceImpl == SearchService.class) {
|
threadPool, scriptModule.getScriptService(), bigArrays, searchModule.getFetchPhase()));
|
||||||
b.bind(SearchService.class).asEagerSingleton();
|
|
||||||
} else {
|
|
||||||
b.bind(SearchService.class).to(searchServiceImpl).asEagerSingleton();
|
|
||||||
}
|
|
||||||
pluginComponents.stream().forEach(p -> b.bind((Class) p.getClass()).toInstance(p));
|
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() {
|
protected SearchService newSearchService(ClusterService clusterService, IndicesService indicesService,
|
||||||
return SearchService.class;
|
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.parent(request.param("parent"));
|
||||||
getRequest.preference(request.param("preference"));
|
getRequest.preference(request.param("preference"));
|
||||||
getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime()));
|
getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime()));
|
||||||
getRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));
|
|
||||||
|
|
||||||
String sField = request.param("fields");
|
String sField = request.param("fields");
|
||||||
if (sField != null) {
|
if (sField != null) {
|
||||||
|
|
|
@ -59,7 +59,6 @@ public class RestMultiGetAction extends BaseRestHandler {
|
||||||
multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
|
multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
|
||||||
multiGetRequest.preference(request.param("preference"));
|
multiGetRequest.preference(request.param("preference"));
|
||||||
multiGetRequest.realtime(request.paramAsBoolean("realtime", multiGetRequest.realtime()));
|
multiGetRequest.realtime(request.paramAsBoolean("realtime", multiGetRequest.realtime()));
|
||||||
multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));
|
|
||||||
|
|
||||||
String[] sFields = null;
|
String[] sFields = null;
|
||||||
String sField = request.param("fields");
|
String sField = request.param("fields");
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.search.internal;
|
package org.elasticsearch.search;
|
||||||
|
|
||||||
import org.apache.lucene.queries.TermsQuery;
|
import org.apache.lucene.queries.TermsQuery;
|
||||||
import org.apache.lucene.search.BooleanClause.Occur;
|
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.shard.IndexShard;
|
||||||
import org.elasticsearch.index.similarity.SimilarityService;
|
import org.elasticsearch.index.similarity.SimilarityService;
|
||||||
import org.elasticsearch.script.ScriptService;
|
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.aggregations.SearchContextAggregations;
|
||||||
import org.elasticsearch.search.dfs.DfsSearchResult;
|
import org.elasticsearch.search.dfs.DfsSearchResult;
|
||||||
import org.elasticsearch.search.fetch.FetchPhase;
|
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.FetchSourceContext;
|
||||||
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext;
|
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext;
|
||||||
import org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight;
|
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.lookup.SearchLookup;
|
||||||
import org.elasticsearch.search.profile.Profilers;
|
import org.elasticsearch.search.profile.Profilers;
|
||||||
import org.elasticsearch.search.query.QueryPhaseExecutionException;
|
import org.elasticsearch.search.query.QueryPhaseExecutionException;
|
||||||
|
@ -80,7 +82,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DefaultSearchContext extends SearchContext {
|
final class DefaultSearchContext extends SearchContext {
|
||||||
|
|
||||||
private final long id;
|
private final long id;
|
||||||
private final ShardSearchRequest request;
|
private final ShardSearchRequest request;
|
||||||
|
@ -123,10 +125,7 @@ public class DefaultSearchContext extends SearchContext {
|
||||||
* things like the type filter or alias filters.
|
* things like the type filter or alias filters.
|
||||||
*/
|
*/
|
||||||
private ParsedQuery originalQuery;
|
private ParsedQuery originalQuery;
|
||||||
/**
|
|
||||||
* Just like originalQuery but with the filters from types, aliases and slice applied.
|
|
||||||
*/
|
|
||||||
private ParsedQuery filteredQuery;
|
|
||||||
/**
|
/**
|
||||||
* The query to actually execute.
|
* The query to actually execute.
|
||||||
*/
|
*/
|
||||||
|
@ -151,7 +150,7 @@ public class DefaultSearchContext extends SearchContext {
|
||||||
private final QueryShardContext queryShardContext;
|
private final QueryShardContext queryShardContext;
|
||||||
private FetchPhase fetchPhase;
|
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,
|
IndexService indexService, IndexShard indexShard, ScriptService scriptService,
|
||||||
BigArrays bigArrays, Counter timeEstimateCounter, ParseFieldMatcher parseFieldMatcher, TimeValue timeout,
|
BigArrays bigArrays, Counter timeEstimateCounter, ParseFieldMatcher parseFieldMatcher, TimeValue timeout,
|
||||||
FetchPhase fetchPhase) {
|
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.
|
* Should be called before executing the main query and after all other parameters have been set.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void preProcess() {
|
public void preProcess(boolean rewrite) {
|
||||||
if (hasOnlySuggest() ) {
|
if (hasOnlySuggest() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -241,20 +240,22 @@ public class DefaultSearchContext extends SearchContext {
|
||||||
if (queryBoost() != AbstractQueryBuilder.DEFAULT_BOOST) {
|
if (queryBoost() != AbstractQueryBuilder.DEFAULT_BOOST) {
|
||||||
parsedQuery(new ParsedQuery(new FunctionScoreQuery(query(), new WeightFactorFunction(queryBoost)), parsedQuery()));
|
parsedQuery(new ParsedQuery(new FunctionScoreQuery(query(), new WeightFactorFunction(queryBoost)), parsedQuery()));
|
||||||
}
|
}
|
||||||
filteredQuery(buildFilteredQuery());
|
this.query = buildFilteredQuery();
|
||||||
try {
|
if (rewrite) {
|
||||||
this.query = searcher().rewrite(this.query);
|
try {
|
||||||
} catch (IOException e) {
|
this.query = searcher.rewrite(query);
|
||||||
throw new QueryPhaseExecutionException(this, "Failed to rewrite main query", e);
|
} catch (IOException e) {
|
||||||
|
throw new QueryPhaseExecutionException(this, "Failed to rewrite main query", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ParsedQuery buildFilteredQuery() {
|
private Query buildFilteredQuery() {
|
||||||
Query searchFilter = searchFilter(queryShardContext.getTypes());
|
final Query searchFilter = searchFilter(queryShardContext.getTypes());
|
||||||
if (searchFilter == null) {
|
if (searchFilter == null) {
|
||||||
return originalQuery;
|
return originalQuery.query();
|
||||||
}
|
}
|
||||||
Query result;
|
final Query result;
|
||||||
if (Queries.isConstantMatchAllQuery(query())) {
|
if (Queries.isConstantMatchAllQuery(query())) {
|
||||||
result = new ConstantScoreQuery(searchFilter);
|
result = new ConstantScoreQuery(searchFilter);
|
||||||
} else {
|
} else {
|
||||||
|
@ -263,7 +264,7 @@ public class DefaultSearchContext extends SearchContext {
|
||||||
.add(searchFilter, Occur.FILTER)
|
.add(searchFilter, Occur.FILTER)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
return new ParsedQuery(result, originalQuery);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -618,15 +619,6 @@ public class DefaultSearchContext extends SearchContext {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParsedQuery filteredQuery() {
|
|
||||||
return filteredQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void filteredQuery(ParsedQuery filteredQuery) {
|
|
||||||
this.filteredQuery = filteredQuery;
|
|
||||||
this.query = filteredQuery.query();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParsedQuery parsedQuery() {
|
public ParsedQuery parsedQuery() {
|
||||||
return this.originalQuery;
|
return this.originalQuery;
|
|
@ -95,7 +95,6 @@ import org.elasticsearch.plugins.SearchPlugin.QuerySpec;
|
||||||
import org.elasticsearch.plugins.SearchPlugin.ScoreFunctionSpec;
|
import org.elasticsearch.plugins.SearchPlugin.ScoreFunctionSpec;
|
||||||
import org.elasticsearch.plugins.SearchPlugin.SearchExtSpec;
|
import org.elasticsearch.plugins.SearchPlugin.SearchExtSpec;
|
||||||
import org.elasticsearch.plugins.SearchPlugin.SearchExtensionSpec;
|
import org.elasticsearch.plugins.SearchPlugin.SearchExtensionSpec;
|
||||||
import org.elasticsearch.search.action.SearchTransportService;
|
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilder;
|
import org.elasticsearch.search.aggregations.AggregationBuilder;
|
||||||
import org.elasticsearch.search.aggregations.Aggregator;
|
import org.elasticsearch.search.aggregations.Aggregator;
|
||||||
import org.elasticsearch.search.aggregations.AggregatorParsers;
|
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.movavg.models.SimpleModel;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregationBuilder;
|
import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregationBuilder;
|
||||||
import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator;
|
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.FetchPhase;
|
||||||
import org.elasticsearch.search.fetch.FetchSubPhase;
|
import org.elasticsearch.search.fetch.FetchSubPhase;
|
||||||
import org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase;
|
import org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase;
|
||||||
|
@ -384,7 +382,6 @@ public class SearchModule extends AbstractModule {
|
||||||
bind(IndicesQueriesRegistry.class).toInstance(queryParserRegistry);
|
bind(IndicesQueriesRegistry.class).toInstance(queryParserRegistry);
|
||||||
bind(SearchRequestParsers.class).toInstance(searchRequestParsers);
|
bind(SearchRequestParsers.class).toInstance(searchRequestParsers);
|
||||||
bind(SearchExtRegistry.class).toInstance(searchExtParserRegistry);
|
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() {
|
private void registerShapes() {
|
||||||
if (ShapesAvailability.JTS_AVAILABLE && ShapesAvailability.SPATIAL4J_AVAILABLE) {
|
if (ShapesAvailability.JTS_AVAILABLE && ShapesAvailability.SPATIAL4J_AVAILABLE) {
|
||||||
ShapeBuilders.register(namedWriteables);
|
ShapeBuilders.register(namedWriteables);
|
||||||
|
@ -817,4 +807,8 @@ public class SearchModule extends AbstractModule {
|
||||||
queryParserRegistry.register(spec.getParser(), spec.getName());
|
queryParserRegistry.register(spec.getParser(), spec.getName());
|
||||||
namedWriteables.add(new Entry(QueryBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
|
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.Nullable;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
|
||||||
import org.elasticsearch.common.lucene.Lucene;
|
import org.elasticsearch.common.lucene.Lucene;
|
||||||
import org.elasticsearch.common.settings.ClusterSettings;
|
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
import org.elasticsearch.common.settings.Setting.Property;
|
import org.elasticsearch.common.settings.Setting.Property;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
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.DocValueFieldsContext;
|
||||||
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField;
|
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField;
|
||||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
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.InternalScrollSearchRequest;
|
||||||
import org.elasticsearch.search.internal.ScrollContext;
|
import org.elasticsearch.search.internal.ScrollContext;
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
|
@ -141,10 +138,9 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
||||||
|
|
||||||
private final ParseFieldMatcher parseFieldMatcher;
|
private final ParseFieldMatcher parseFieldMatcher;
|
||||||
|
|
||||||
@Inject
|
public SearchService(ClusterService clusterService, IndicesService indicesService,
|
||||||
public SearchService(Settings settings, ClusterSettings clusterSettings, ClusterService clusterService, IndicesService indicesService,
|
|
||||||
ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase) {
|
ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase) {
|
||||||
super(settings);
|
super(clusterService.getSettings());
|
||||||
this.parseFieldMatcher = new ParseFieldMatcher(settings);
|
this.parseFieldMatcher = new ParseFieldMatcher(settings);
|
||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
this.clusterService = clusterService;
|
this.clusterService = clusterService;
|
||||||
|
@ -160,7 +156,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
||||||
this.keepAliveReaper = threadPool.scheduleWithFixedDelay(new Reaper(), keepAliveInterval, Names.SAME);
|
this.keepAliveReaper = threadPool.scheduleWithFixedDelay(new Reaper(), keepAliveInterval, Names.SAME);
|
||||||
|
|
||||||
defaultSearchTimeout = DEFAULT_SEARCH_TIMEOUT_SETTING.get(settings);
|
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) {
|
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 {
|
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 = createSearchContext(request, defaultSearchTimeout, searcher);
|
||||||
|
|
||||||
DefaultSearchContext context = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher,
|
|
||||||
indexService,
|
|
||||||
indexShard, scriptService, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher,
|
|
||||||
defaultSearchTimeout, fetchPhase);
|
|
||||||
SearchContext.setCurrent(context);
|
SearchContext.setCurrent(context);
|
||||||
try {
|
try {
|
||||||
request.rewrite(context.getQueryShardContext());
|
request.rewrite(context.getQueryShardContext());
|
||||||
|
@ -572,6 +560,18 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
||||||
return context;
|
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) {
|
private void freeAllContextForIndex(Index index) {
|
||||||
assert index != null;
|
assert index != null;
|
||||||
for (SearchContext ctx : activeContexts.values()) {
|
for (SearchContext ctx : activeContexts.values()) {
|
||||||
|
|
|
@ -100,8 +100,8 @@ public abstract class FilteredSearchContext extends SearchContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preProcess() {
|
public void preProcess(boolean rewrite) {
|
||||||
in.preProcess();
|
in.preProcess(rewrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.
|
* 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);
|
public abstract Query searchFilter(String[] types);
|
||||||
|
|
||||||
|
|
|
@ -81,14 +81,11 @@ public class ShardSearchLocalRequest implements ShardSearchRequest {
|
||||||
this.nowInMillis = nowInMillis;
|
this.nowInMillis = nowInMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardSearchLocalRequest(String[] types, long nowInMillis) {
|
public ShardSearchLocalRequest(ShardId shardId, String[] types, long nowInMillis, String[] filteringAliases) {
|
||||||
this.types = types;
|
this.types = types;
|
||||||
this.nowInMillis = nowInMillis;
|
this.nowInMillis = nowInMillis;
|
||||||
}
|
|
||||||
|
|
||||||
public ShardSearchLocalRequest(String[] types, long nowInMillis, String[] filteringAliases) {
|
|
||||||
this(types, nowInMillis);
|
|
||||||
this.filteringAliases = filteringAliases;
|
this.filteringAliases = filteringAliases;
|
||||||
|
this.shardId = shardId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardSearchLocalRequest(ShardId shardId, int numberOfShards, SearchType searchType, SearchSourceBuilder source, String[] types,
|
public ShardSearchLocalRequest(ShardId shardId, int numberOfShards, SearchType searchType, SearchSourceBuilder source, String[] types,
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class SubSearchContext extends FilteredSearchContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preProcess() {
|
public void preProcess(boolean rewrite) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class QueryPhase implements SearchPhase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preProcess(SearchContext context) {
|
public void preProcess(SearchContext context) {
|
||||||
context.preProcess();
|
context.preProcess(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -86,7 +86,7 @@ import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.script.MockScriptPlugin;
|
import org.elasticsearch.script.MockScriptPlugin;
|
||||||
import org.elasticsearch.script.Script;
|
import org.elasticsearch.script.Script;
|
||||||
import org.elasticsearch.script.ScriptService;
|
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.tasks.Task;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||||
|
|
|
@ -42,8 +42,6 @@ public class MultiGetShardRequestTests extends ESTestCase {
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
multiGetRequest.refresh(true);
|
multiGetRequest.refresh(true);
|
||||||
}
|
}
|
||||||
multiGetRequest.ignoreErrorsOnGeneratedFields(randomBoolean());
|
|
||||||
|
|
||||||
MultiGetShardRequest multiGetShardRequest = new MultiGetShardRequest(multiGetRequest, "index", 0);
|
MultiGetShardRequest multiGetShardRequest = new MultiGetShardRequest(multiGetRequest, "index", 0);
|
||||||
int numItems = iterations(10, 30);
|
int numItems = iterations(10, 30);
|
||||||
for (int i = 0; i < numItems; i++) {
|
for (int i = 0; i < numItems; i++) {
|
||||||
|
@ -79,7 +77,6 @@ public class MultiGetShardRequestTests extends ESTestCase {
|
||||||
assertThat(multiGetShardRequest2.preference(), equalTo(multiGetShardRequest.preference()));
|
assertThat(multiGetShardRequest2.preference(), equalTo(multiGetShardRequest.preference()));
|
||||||
assertThat(multiGetShardRequest2.realtime(), equalTo(multiGetShardRequest.realtime()));
|
assertThat(multiGetShardRequest2.realtime(), equalTo(multiGetShardRequest.realtime()));
|
||||||
assertThat(multiGetShardRequest2.refresh(), equalTo(multiGetShardRequest.refresh()));
|
assertThat(multiGetShardRequest2.refresh(), equalTo(multiGetShardRequest.refresh()));
|
||||||
assertThat(multiGetShardRequest2.ignoreErrorsOnGeneratedFields(), equalTo(multiGetShardRequest.ignoreErrorsOnGeneratedFields()));
|
|
||||||
assertThat(multiGetShardRequest2.items.size(), equalTo(multiGetShardRequest.items.size()));
|
assertThat(multiGetShardRequest2.items.size(), equalTo(multiGetShardRequest.items.size()));
|
||||||
for (int i = 0; i < multiGetShardRequest2.items.size(); i++) {
|
for (int i = 0; i < multiGetShardRequest2.items.size(); i++) {
|
||||||
MultiGetRequest.Item item = multiGetShardRequest.items.get(i);
|
MultiGetRequest.Item item = multiGetShardRequest.items.get(i);
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.search.controller;
|
package org.elasticsearch.action.search;
|
||||||
|
|
||||||
import org.apache.lucene.search.ScoreDoc;
|
import org.apache.lucene.search.ScoreDoc;
|
||||||
import org.apache.lucene.search.TopDocs;
|
import org.apache.lucene.search.TopDocs;
|
||||||
|
import org.elasticsearch.action.search.SearchPhaseController;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.text.Text;
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.common.util.BigArrays;
|
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) {
|
private void assertGetFieldsAlwaysWorks(String index, String type, String docId, String[] fields, @Nullable String routing) {
|
||||||
for (String field : fields) {
|
for (String field : fields) {
|
||||||
assertGetFieldWorks(index, type, docId, field, false, routing);
|
assertGetFieldWorks(index, type, docId, field, routing);
|
||||||
assertGetFieldWorks(index, type, docId, field, true, routing);
|
assertGetFieldWorks(index, type, docId, field, routing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertGetFieldWorks(String index, String type, String docId, String field, boolean ignoreErrors, @Nullable String routing) {
|
private void assertGetFieldWorks(String index, String type, String docId, String field, @Nullable String routing) {
|
||||||
GetResponse response = getDocument(index, type, docId, field, ignoreErrors, routing);
|
GetResponse response = getDocument(index, type, docId, field, routing);
|
||||||
assertThat(response.getId(), equalTo(docId));
|
assertThat(response.getId(), equalTo(docId));
|
||||||
assertTrue(response.isExists());
|
assertTrue(response.isExists());
|
||||||
assertNotNull(response.getField(field));
|
assertNotNull(response.getField(field));
|
||||||
response = multiGetDocument(index, type, docId, field, ignoreErrors, routing);
|
response = multiGetDocument(index, type, docId, field, routing);
|
||||||
assertThat(response.getId(), equalTo(docId));
|
assertThat(response.getId(), equalTo(docId));
|
||||||
assertTrue(response.isExists());
|
assertTrue(response.isExists());
|
||||||
assertNotNull(response.getField(field));
|
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) {
|
private void assertGetFieldException(String index, String type, String docId, String field) {
|
||||||
try {
|
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();
|
fail();
|
||||||
} catch (ElasticsearchException e) {
|
} catch (ElasticsearchException e) {
|
||||||
assertTrue(e.getMessage().contains("You can only get this field after refresh() has been called."));
|
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());
|
assertNull(multiGetResponse.getResponses()[0].getResponse());
|
||||||
assertTrue(multiGetResponse.getResponses()[0].getFailure().getMessage().contains("You can only get this field after refresh() has been called."));
|
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) {
|
protected void assertGetFieldsNull(String index, String type, String docId, String[] fields, @Nullable String routing) {
|
||||||
for (String field : fields) {
|
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) {
|
protected void assertGetFieldsAlwaysNull(String index, String type, String docId, String[] fields, @Nullable String routing) {
|
||||||
for (String field : fields) {
|
for (String field : fields) {
|
||||||
assertGetFieldNull(index, type, docId, field, true, routing);
|
assertGetFieldNull(index, type, docId, field, routing);
|
||||||
assertGetFieldNull(index, type, docId, field, false, 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
|
//for get
|
||||||
GetResponse response = getDocument(index, type, docId, field, ignoreErrors, routing);
|
GetResponse response = getDocument(index, type, docId, field, routing);
|
||||||
assertTrue(response.isExists());
|
assertTrue(response.isExists());
|
||||||
assertNull(response.getField(field));
|
assertNull(response.getField(field));
|
||||||
assertThat(response.getId(), equalTo(docId));
|
assertThat(response.getId(), equalTo(docId));
|
||||||
//same for multi get
|
//same for multi get
|
||||||
response = multiGetDocument(index, type, docId, field, ignoreErrors, routing);
|
response = multiGetDocument(index, type, docId, field, routing);
|
||||||
assertNull(response.getField(field));
|
assertNull(response.getField(field));
|
||||||
assertThat(response.getId(), equalTo(docId));
|
assertThat(response.getId(), equalTo(docId));
|
||||||
assertTrue(response.isExists());
|
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);
|
MultiGetRequest.Item getItem = new MultiGetRequest.Item(index, type, docId).fields(field);
|
||||||
if (routing != null) {
|
if (routing != null) {
|
||||||
getItem.routing(routing);
|
getItem.routing(routing);
|
||||||
}
|
}
|
||||||
MultiGetRequestBuilder multiGetRequestBuilder = client().prepareMultiGet().add(getItem).setIgnoreErrorsOnGeneratedFields(ignoreErrors);
|
MultiGetRequestBuilder multiGetRequestBuilder = client().prepareMultiGet().add(getItem);
|
||||||
MultiGetResponse multiGetResponse = multiGetRequestBuilder.get();
|
MultiGetResponse multiGetResponse = multiGetRequestBuilder.get();
|
||||||
assertThat(multiGetResponse.getResponses().length, equalTo(1));
|
assertThat(multiGetResponse.getResponses().length, equalTo(1));
|
||||||
return multiGetResponse.getResponses()[0].getResponse();
|
return multiGetResponse.getResponses()[0].getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GetResponse getDocument(String index, String type, String docId, String field, boolean ignoreErrors, @Nullable String routing) {
|
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).setIgnoreErrorsOnGeneratedFields(ignoreErrors);
|
GetRequestBuilder getRequestBuilder = client().prepareGet().setIndex(index).setType(type).setId(docId).setFields(field);
|
||||||
if (routing != null) {
|
if (routing != null) {
|
||||||
getRequestBuilder.setRouting(routing);
|
getRequestBuilder.setRouting(routing);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.search.internal;
|
package org.elasticsearch.search;
|
||||||
|
|
||||||
import org.apache.lucene.queries.TermsQuery;
|
import org.apache.lucene.queries.TermsQuery;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
|
@ -26,6 +26,7 @@ import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.common.lucene.search.Queries;
|
import org.elasticsearch.common.lucene.search.Queries;
|
||||||
import org.elasticsearch.index.mapper.TypeFieldMapper;
|
import org.elasticsearch.index.mapper.TypeFieldMapper;
|
||||||
|
import org.elasticsearch.search.DefaultSearchContext;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
|
||||||
import static org.apache.lucene.search.BooleanClause.Occur.FILTER;
|
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,
|
SearchModule searchModule = new SearchModule(Settings.EMPTY, false,
|
||||||
Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin())) {
|
Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin()));
|
||||||
@Override
|
|
||||||
protected void configureSearch() {
|
|
||||||
// Skip me
|
|
||||||
}
|
|
||||||
};
|
|
||||||
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||||
entries.addAll(indicesModule.getNamedWriteables());
|
entries.addAll(indicesModule.getNamedWriteables());
|
||||||
entries.addAll(searchModule.getNamedWriteables());
|
entries.addAll(searchModule.getNamedWriteables());
|
||||||
|
|
|
@ -119,12 +119,7 @@ public class AggregatorParsingTests extends ESTestCase {
|
||||||
bindMapperExtension();
|
bindMapperExtension();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SearchModule searchModule = new SearchModule(settings, false, emptyList()) {
|
SearchModule searchModule = new SearchModule(settings, false, emptyList());
|
||||||
@Override
|
|
||||||
protected void configureSearch() {
|
|
||||||
// Skip me
|
|
||||||
}
|
|
||||||
};
|
|
||||||
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||||
entries.addAll(indicesModule.getNamedWriteables());
|
entries.addAll(indicesModule.getNamedWriteables());
|
||||||
entries.addAll(searchModule.getNamedWriteables());
|
entries.addAll(searchModule.getNamedWriteables());
|
||||||
|
|
|
@ -143,12 +143,7 @@ public abstract class BaseAggregationTestCase<AB extends AbstractAggregationBuil
|
||||||
bindMapperExtension();
|
bindMapperExtension();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SearchModule searchModule = new SearchModule(settings, false, emptyList()) {
|
SearchModule searchModule = new SearchModule(settings, false, emptyList());
|
||||||
@Override
|
|
||||||
protected void configureSearch() {
|
|
||||||
// Skip me
|
|
||||||
}
|
|
||||||
};
|
|
||||||
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||||
entries.addAll(indicesModule.getNamedWriteables());
|
entries.addAll(indicesModule.getNamedWriteables());
|
||||||
entries.addAll(searchModule.getNamedWriteables());
|
entries.addAll(searchModule.getNamedWriteables());
|
||||||
|
|
|
@ -133,12 +133,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SearchModule searchModule = new SearchModule(settings, false,
|
SearchModule searchModule = new SearchModule(settings, false,
|
||||||
Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin())) {
|
Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin()));
|
||||||
@Override
|
|
||||||
protected void configureSearch() {
|
|
||||||
// Skip me
|
|
||||||
}
|
|
||||||
};
|
|
||||||
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||||
entries.addAll(indicesModule.getNamedWriteables());
|
entries.addAll(indicesModule.getNamedWriteables());
|
||||||
entries.addAll(searchModule.getNamedWriteables());
|
entries.addAll(searchModule.getNamedWriteables());
|
||||||
|
|
|
@ -59,12 +59,7 @@ public class ShardSearchTransportRequestTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SearchModule searchModule = new SearchModule(Settings.EMPTY, false,
|
SearchModule searchModule = new SearchModule(Settings.EMPTY, false,
|
||||||
Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin())) {
|
Collections.singletonList(new FetchSubPhasePluginIT.FetchTermVectorsPlugin()));
|
||||||
@Override
|
|
||||||
protected void configureSearch() {
|
|
||||||
// Skip me
|
|
||||||
}
|
|
||||||
};
|
|
||||||
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||||
entries.addAll(indicesModule.getNamedWriteables());
|
entries.addAll(indicesModule.getNamedWriteables());
|
||||||
entries.addAll(searchModule.getNamedWriteables());
|
entries.addAll(searchModule.getNamedWriteables());
|
||||||
|
|
|
@ -19,18 +19,21 @@
|
||||||
|
|
||||||
package org.elasticsearch.node;
|
package org.elasticsearch.node;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.BigArrays;
|
import org.elasticsearch.common.util.BigArrays;
|
||||||
import org.elasticsearch.common.util.MockBigArrays;
|
import org.elasticsearch.common.util.MockBigArrays;
|
||||||
|
import org.elasticsearch.indices.IndicesService;
|
||||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||||
import org.elasticsearch.node.internal.InternalSettingsPreparer;
|
import org.elasticsearch.node.internal.InternalSettingsPreparer;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.plugins.SearchPlugin;
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.search.MockSearchService;
|
import org.elasticsearch.search.MockSearchService;
|
||||||
import org.elasticsearch.search.SearchService;
|
import org.elasticsearch.search.SearchService;
|
||||||
|
import org.elasticsearch.search.fetch.FetchPhase;
|
||||||
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A node for testing which allows:
|
* A node for testing which allows:
|
||||||
|
@ -62,11 +65,15 @@ public class MockNode extends Node {
|
||||||
return new MockBigArrays(settings, circuitBreakerService);
|
return new MockBigArrays(settings, circuitBreakerService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@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()) {
|
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;
|
package org.elasticsearch.search;
|
||||||
|
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
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.common.util.BigArrays;
|
||||||
import org.elasticsearch.indices.IndicesService;
|
import org.elasticsearch.indices.IndicesService;
|
||||||
import org.elasticsearch.node.MockNode;
|
import org.elasticsearch.node.MockNode;
|
||||||
|
@ -69,11 +66,10 @@ public class MockSearchService extends SearchService {
|
||||||
ACTIVE_SEARCH_CONTEXTS.remove(context);
|
ACTIVE_SEARCH_CONTEXTS.remove(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
public MockSearchService(ClusterService clusterService,
|
||||||
public MockSearchService(Settings settings, ClusterSettings clusterSettings, ClusterService clusterService,
|
|
||||||
IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService,
|
IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService,
|
||||||
BigArrays bigArrays, FetchPhase fetchPhase) {
|
BigArrays bigArrays, FetchPhase fetchPhase) {
|
||||||
super(settings, clusterSettings, clusterService, indicesService, threadPool, scriptService, bigArrays, fetchPhase);
|
super(clusterService, indicesService, threadPool, scriptService, bigArrays, fetchPhase);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1045,12 +1045,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
||||||
scriptSettings.addAll(pluginsService.getPluginSettings());
|
scriptSettings.addAll(pluginsService.getPluginSettings());
|
||||||
scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED);
|
scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED);
|
||||||
SettingsModule settingsModule = new SettingsModule(nodeSettings, scriptSettings, pluginsService.getPluginSettingsFilter());
|
SettingsModule settingsModule = new SettingsModule(nodeSettings, scriptSettings, pluginsService.getPluginSettingsFilter());
|
||||||
searchModule = new SearchModule(nodeSettings, false, pluginsService.filterPlugins(SearchPlugin.class)) {
|
searchModule = new SearchModule(nodeSettings, false, pluginsService.filterPlugins(SearchPlugin.class));
|
||||||
@Override
|
|
||||||
protected void configureSearch() {
|
|
||||||
// Skip me
|
|
||||||
}
|
|
||||||
};
|
|
||||||
IndicesModule indicesModule = new IndicesModule(pluginsService.filterPlugins(MapperPlugin.class)) {
|
IndicesModule indicesModule = new IndicesModule(pluginsService.filterPlugins(MapperPlugin.class)) {
|
||||||
@Override
|
@Override
|
||||||
public void configure() {
|
public void configure() {
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class TestSearchContext extends SearchContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preProcess() {
|
public void preProcess(boolean rewrite) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue