review comment fixes
This commit is contained in:
parent
c618f75b76
commit
63c51b78b2
|
@ -100,6 +100,7 @@ public class SearchRequest extends ActionRequest<SearchRequest> implements Indic
|
||||||
*/
|
*/
|
||||||
public SearchRequest(ActionRequest request) {
|
public SearchRequest(ActionRequest request) {
|
||||||
super(request);
|
super(request);
|
||||||
|
this.source = new SearchSourceBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,7 +108,7 @@ public class SearchRequest extends ActionRequest<SearchRequest> implements Indic
|
||||||
* will run against all indices.
|
* will run against all indices.
|
||||||
*/
|
*/
|
||||||
public SearchRequest(String... indices) {
|
public SearchRequest(String... indices) {
|
||||||
indices(indices);
|
this(indices, new SearchSourceBuilder());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -331,9 +332,7 @@ public class SearchRequest extends ActionRequest<SearchRequest> implements Indic
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
scroll = readScroll(in);
|
scroll = readScroll(in);
|
||||||
}
|
}
|
||||||
if (in.readBoolean()) {
|
source = SearchSourceBuilder.readSearchSourceFrom(in);
|
||||||
source = SearchSourceBuilder.readSearchSourceFrom(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
types = in.readStringArray();
|
types = in.readStringArray();
|
||||||
indicesOptions = IndicesOptions.readIndicesOptions(in);
|
indicesOptions = IndicesOptions.readIndicesOptions(in);
|
||||||
|
@ -361,12 +360,7 @@ public class SearchRequest extends ActionRequest<SearchRequest> implements Indic
|
||||||
out.writeBoolean(true);
|
out.writeBoolean(true);
|
||||||
scroll.writeTo(out);
|
scroll.writeTo(out);
|
||||||
}
|
}
|
||||||
if (source == null) {
|
source.writeTo(out);
|
||||||
out.writeBoolean(false);
|
|
||||||
} else {
|
|
||||||
out.writeBoolean(true);
|
|
||||||
source.writeTo(out);
|
|
||||||
}
|
|
||||||
out.writeStringArray(types);
|
out.writeStringArray(types);
|
||||||
indicesOptions.writeIndicesOptions(out);
|
indicesOptions.writeIndicesOptions(out);
|
||||||
out.writeOptionalBoolean(requestCache);
|
out.writeOptionalBoolean(requestCache);
|
||||||
|
|
|
@ -353,10 +353,10 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the fields to load and return as part of the search request. If none are specified,
|
* Sets the fields to load and return as part of the search request. If none
|
||||||
* the source of the document will be returned.
|
* are specified, the source of the document will be returned.
|
||||||
*/
|
*/
|
||||||
public SearchRequestBuilder addFields(String... fields) {
|
public SearchRequestBuilder fields(String... fields) {
|
||||||
sourceBuilder().fields(Arrays.asList(fields));
|
sourceBuilder().fields(Arrays.asList(fields));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class RestPutWarmerAction extends BaseRestHandler {
|
||||||
PutWarmerRequest putWarmerRequest = new PutWarmerRequest(request.param("name"));
|
PutWarmerRequest putWarmerRequest = new PutWarmerRequest(request.param("name"));
|
||||||
|
|
||||||
BytesReference sourceBytes = RestActions.getRestContent(request);
|
BytesReference sourceBytes = RestActions.getRestContent(request);
|
||||||
SearchSourceBuilder source = RestActions.getRestSearchSource(sourceBytes, queryRegistry);
|
SearchSourceBuilder source = RestActions.getRestSearchSource(sourceBytes, queryRegistry, parseFieldMatcher);
|
||||||
SearchRequest searchRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")))
|
SearchRequest searchRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")))
|
||||||
.types(Strings.splitStringByCommaToArray(request.param("type")))
|
.types(Strings.splitStringByCommaToArray(request.param("type")))
|
||||||
.requestCache(request.paramAsBoolean("request_cache", null)).source(source);
|
.requestCache(request.paramAsBoolean("request_cache", null)).source(source);
|
||||||
|
|
|
@ -70,6 +70,7 @@ public class RestCountAction extends AbstractCatAction {
|
||||||
String source = request.param("source");
|
String source = request.param("source");
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
||||||
|
context.parseFieldMatcher(parseFieldMatcher);
|
||||||
countRequest.query(RestActions.getQueryContent(new BytesArray(source), context));
|
countRequest.query(RestActions.getQueryContent(new BytesArray(source), context));
|
||||||
} else {
|
} else {
|
||||||
QueryBuilder<?> queryBuilder = RestActions.urlParamsToQueryBuilder(request);
|
QueryBuilder<?> queryBuilder = RestActions.urlParamsToQueryBuilder(request);
|
||||||
|
|
|
@ -71,6 +71,7 @@ public class RestCountAction extends BaseRestHandler {
|
||||||
if (RestActions.hasBodyContent(request)) {
|
if (RestActions.hasBodyContent(request)) {
|
||||||
BytesReference restContent = RestActions.getRestContent(request);
|
BytesReference restContent = RestActions.getRestContent(request);
|
||||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
||||||
|
context.parseFieldMatcher(parseFieldMatcher);
|
||||||
countRequest.query(RestActions.getQueryContent(restContent, context));
|
countRequest.query(RestActions.getQueryContent(restContent, context));
|
||||||
} else {
|
} else {
|
||||||
QueryBuilder<?> queryBuilder = RestActions.urlParamsToQueryBuilder(request);
|
QueryBuilder<?> queryBuilder = RestActions.urlParamsToQueryBuilder(request);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.action.support.IndicesOptions;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
@ -90,7 +91,9 @@ public class RestMultiSearchAction extends BaseRestHandler {
|
||||||
String path = request.path();
|
String path = request.path();
|
||||||
boolean isTemplateRequest = isTemplateRequest(path);
|
boolean isTemplateRequest = isTemplateRequest(path);
|
||||||
IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, multiSearchRequest.indicesOptions());
|
IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, multiSearchRequest.indicesOptions());
|
||||||
parseRequest(multiSearchRequest, RestActions.getRestContent(request), isTemplateRequest, indices, types, request.param("search_type"), request.param("routing"), indicesOptions, allowExplicitIndex, indicesQueriesRegistry);
|
parseRequest(multiSearchRequest, RestActions.getRestContent(request), isTemplateRequest, indices, types,
|
||||||
|
request.param("search_type"), request.param("routing"), indicesOptions, allowExplicitIndex, indicesQueriesRegistry,
|
||||||
|
parseFieldMatcher);
|
||||||
client.multiSearch(multiSearchRequest, new RestToXContentListener<>(channel));
|
client.multiSearch(multiSearchRequest, new RestToXContentListener<>(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +107,8 @@ public class RestMultiSearchAction extends BaseRestHandler {
|
||||||
@Nullable String searchType,
|
@Nullable String searchType,
|
||||||
@Nullable String routing,
|
@Nullable String routing,
|
||||||
IndicesOptions indicesOptions,
|
IndicesOptions indicesOptions,
|
||||||
boolean allowExplicitIndex, IndicesQueriesRegistry indicesQueriesRegistry) throws Exception {
|
boolean allowExplicitIndex, IndicesQueriesRegistry indicesQueriesRegistry,
|
||||||
|
ParseFieldMatcher parseFieldMatcher) throws Exception {
|
||||||
XContent xContent = XContentFactory.xContent(data);
|
XContent xContent = XContentFactory.xContent(data);
|
||||||
int from = 0;
|
int from = 0;
|
||||||
int length = data.length();
|
int length = data.length();
|
||||||
|
@ -178,6 +182,7 @@ public class RestMultiSearchAction extends BaseRestHandler {
|
||||||
if (isTemplateRequest) {
|
if (isTemplateRequest) {
|
||||||
try (XContentParser parser = XContentFactory.xContent(slice).createParser(slice)) {
|
try (XContentParser parser = XContentFactory.xContent(slice).createParser(slice)) {
|
||||||
queryParseContext.reset(parser);
|
queryParseContext.reset(parser);
|
||||||
|
queryParseContext.parseFieldMatcher(parseFieldMatcher);
|
||||||
Template template = TemplateQueryParser.parse(parser, queryParseContext.parseFieldMatcher(), "params", "template");
|
Template template = TemplateQueryParser.parse(parser, queryParseContext.parseFieldMatcher(), "params", "template");
|
||||||
searchRequest.template(template);
|
searchRequest.template(template);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,12 +110,13 @@ public class RestSearchAction extends BaseRestHandler {
|
||||||
if (isTemplateRequest) {
|
if (isTemplateRequest) {
|
||||||
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||||
context.reset(parser);
|
context.reset(parser);
|
||||||
|
context.parseFieldMatcher(parseFieldMatcher);
|
||||||
Template template = TemplateQueryParser.parse(parser, context.parseFieldMatcher(), "params", "template");
|
Template template = TemplateQueryParser.parse(parser, context.parseFieldMatcher(), "params", "template");
|
||||||
searchRequest.template(template);
|
searchRequest.template(template);
|
||||||
}
|
}
|
||||||
builder = null;
|
builder = null;
|
||||||
} else {
|
} else {
|
||||||
builder = RestActions.getRestSearchSource(restContent, indicesQueriesRegistry);
|
builder = RestActions.getRestSearchSource(restContent, indicesQueriesRegistry, parseFieldMatcher);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
builder = null;
|
builder = null;
|
||||||
|
@ -155,7 +156,7 @@ public class RestSearchAction extends BaseRestHandler {
|
||||||
return searchRequest;
|
return searchRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean parseSearchSource(final SearchSourceBuilder searchSourceBuilder, RestRequest request) {
|
private static boolean parseSearchSource(final SearchSourceBuilder searchSourceBuilder, RestRequest request) {
|
||||||
|
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
QueryBuilder<?> queryBuilder = RestActions.urlParamsToQueryBuilder(request);
|
QueryBuilder<?> queryBuilder = RestActions.urlParamsToQueryBuilder(request);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.ExceptionsHelper;
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.action.ShardOperationFailedException;
|
import org.elasticsearch.action.ShardOperationFailedException;
|
||||||
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
||||||
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.lucene.uid.Versions;
|
import org.elasticsearch.common.lucene.uid.Versions;
|
||||||
|
@ -112,11 +113,13 @@ public class RestActions {
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SearchSourceBuilder getRestSearchSource(BytesReference sourceBytes, IndicesQueriesRegistry queryRegistry)
|
public static SearchSourceBuilder getRestSearchSource(BytesReference sourceBytes, IndicesQueriesRegistry queryRegistry,
|
||||||
|
ParseFieldMatcher parseFieldMatcher)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes);
|
XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes);
|
||||||
QueryParseContext queryParseContext = new QueryParseContext(queryRegistry);
|
QueryParseContext queryParseContext = new QueryParseContext(queryRegistry);
|
||||||
queryParseContext.reset(parser);
|
queryParseContext.reset(parser);
|
||||||
|
queryParseContext.parseFieldMatcher(parseFieldMatcher);
|
||||||
SearchSourceBuilder source = SearchSourceBuilder.parseSearchSource(parser, queryParseContext);
|
SearchSourceBuilder source = SearchSourceBuilder.parseSearchSource(parser, queryParseContext);
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
@ -142,7 +145,11 @@ public class RestActions {
|
||||||
|
|
||||||
public static QueryBuilder<?> getQueryContent(BytesReference source, QueryParseContext context) {
|
public static QueryBuilder<?> getQueryContent(BytesReference source, QueryParseContext context) {
|
||||||
try (XContentParser requestParser = XContentFactory.xContent(source).createParser(source)) {
|
try (XContentParser requestParser = XContentFactory.xContent(source).createParser(source)) {
|
||||||
|
// Save the parseFieldMatcher because its about to be trashed in the
|
||||||
|
// QueryParseContext
|
||||||
|
ParseFieldMatcher parseFieldMatcher = context.parseFieldMatcher();
|
||||||
context.reset(requestParser);
|
context.reset(requestParser);
|
||||||
|
context.parseFieldMatcher(parseFieldMatcher);
|
||||||
return context.parseInnerQueryBuilder();
|
return context.parseInnerQueryBuilder();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ElasticsearchException("failed to parse source", e);
|
throw new ElasticsearchException("failed to parse source", e);
|
||||||
|
|
|
@ -578,6 +578,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
try (XContentParser parser = XContentFactory.xContent(run).createParser(run)) {
|
try (XContentParser parser = XContentFactory.xContent(run).createParser(run)) {
|
||||||
QueryParseContext queryParseContext = new QueryParseContext(indexService.queryParserService().indicesQueriesRegistry());
|
QueryParseContext queryParseContext = new QueryParseContext(indexService.queryParserService().indicesQueriesRegistry());
|
||||||
queryParseContext.reset(parser);
|
queryParseContext.reset(parser);
|
||||||
|
queryParseContext.parseFieldMatcher(parseFieldMatcher);
|
||||||
parseSource(context, SearchSourceBuilder.parseSearchSource(parser, queryParseContext));
|
parseSource(context, SearchSourceBuilder.parseSearchSource(parser, queryParseContext));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -673,8 +674,8 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
private void parseSource(SearchContext context, SearchSourceBuilder source) throws SearchParseException {
|
private void parseSource(SearchContext context, SearchSourceBuilder source) throws SearchParseException {
|
||||||
// nothing to parse...
|
// nothing to parse...
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.from(source.from());
|
context.from(source.from());
|
||||||
context.size(source.size());
|
context.size(source.size());
|
||||||
|
@ -686,10 +687,10 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (source.query() != null) {
|
if (source.query() != null) {
|
||||||
context.parsedQuery(context.queryParserService().parse(source.query()));
|
context.parsedQuery(context.queryParserService().toQuery(source.query()));
|
||||||
}
|
}
|
||||||
if (source.postFilter() != null) {
|
if (source.postFilter() != null) {
|
||||||
context.parsedPostFilter(context.queryParserService().parse(source.postFilter()));
|
context.parsedPostFilter(context.queryParserService().toQuery(source.postFilter()));
|
||||||
}
|
}
|
||||||
if (source.sorts() != null) {
|
if (source.sorts() != null) {
|
||||||
XContentParser completeSortParser = null;
|
XContentParser completeSortParser = null;
|
||||||
|
@ -775,7 +776,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
}
|
}
|
||||||
if (source.rescores() != null) {
|
if (source.rescores() != null) {
|
||||||
XContentParser completeRescoreParser = null;
|
XContentParser completeRescoreParser = null;
|
||||||
try {
|
try {
|
||||||
XContentBuilder completeRescoreBuilder = XContentFactory.jsonBuilder();
|
XContentBuilder completeRescoreBuilder = XContentFactory.jsonBuilder();
|
||||||
completeRescoreBuilder.startObject();
|
completeRescoreBuilder.startObject();
|
||||||
completeRescoreBuilder.startArray("rescore");
|
completeRescoreBuilder.startArray("rescore");
|
||||||
|
@ -783,7 +784,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
XContentParser parser = XContentFactory.xContent(rescore).createParser(rescore);
|
XContentParser parser = XContentFactory.xContent(rescore).createParser(rescore);
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
completeRescoreBuilder.copyCurrentStructure(parser);
|
completeRescoreBuilder.copyCurrentStructure(parser);
|
||||||
}
|
}
|
||||||
completeRescoreBuilder.endArray();
|
completeRescoreBuilder.endArray();
|
||||||
completeRescoreBuilder.endObject();
|
completeRescoreBuilder.endObject();
|
||||||
BytesReference completeRescoreBytes = completeRescoreBuilder.bytes();
|
BytesReference completeRescoreBytes = completeRescoreBuilder.bytes();
|
||||||
|
@ -794,7 +795,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
this.elementParsers.get("rescore").parse(completeRescoreParser, context);
|
this.elementParsers.get("rescore").parse(completeRescoreParser, context);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String sSource = "_na_";
|
String sSource = "_na_";
|
||||||
try {
|
try {
|
||||||
sSource = source.toString();
|
sSource = source.toString();
|
||||||
} catch (Throwable e1) {
|
} catch (Throwable e1) {
|
||||||
// ignore
|
// ignore
|
||||||
|
@ -802,23 +803,23 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
XContentLocation location = completeRescoreParser != null ? completeRescoreParser.getTokenLocation() : null;
|
XContentLocation location = completeRescoreParser != null ? completeRescoreParser.getTokenLocation() : null;
|
||||||
throw new SearchParseException(context, "failed to parse rescore source [" + sSource + "]", location, e);
|
throw new SearchParseException(context, "failed to parse rescore source [" + sSource + "]", location, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (source.fields() != null) {
|
if (source.fields() != null) {
|
||||||
context.fieldNames().addAll(source.fields());
|
context.fieldNames().addAll(source.fields());
|
||||||
}
|
}
|
||||||
if (source.explain() != null) {
|
if (source.explain() != null) {
|
||||||
context.explain(source.explain());
|
context.explain(source.explain());
|
||||||
}
|
}
|
||||||
if (source.fetchSource() != null) {
|
if (source.fetchSource() != null) {
|
||||||
context.fetchSourceContext(source.fetchSource());
|
context.fetchSourceContext(source.fetchSource());
|
||||||
}
|
}
|
||||||
if (source.fieldDataFields() != null) {
|
if (source.fieldDataFields() != null) {
|
||||||
FieldDataFieldsContext fieldDataFieldsContext = context.getFetchSubPhaseContext(FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY);
|
FieldDataFieldsContext fieldDataFieldsContext = context.getFetchSubPhaseContext(FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY);
|
||||||
for (String field : source.fieldDataFields()) {
|
for (String field : source.fieldDataFields()) {
|
||||||
fieldDataFieldsContext.add(new FieldDataField(field));
|
fieldDataFieldsContext.add(new FieldDataField(field));
|
||||||
}
|
}
|
||||||
fieldDataFieldsContext.setHitExecutionNeeded(true);
|
fieldDataFieldsContext.setHitExecutionNeeded(true);
|
||||||
}
|
}
|
||||||
if (source.highlighter() != null) {
|
if (source.highlighter() != null) {
|
||||||
XContentParser highlighterParser = null;
|
XContentParser highlighterParser = null;
|
||||||
try {
|
try {
|
||||||
|
@ -830,10 +831,10 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
sSource = source.toString();
|
sSource = source.toString();
|
||||||
} catch (Throwable e1) {
|
} catch (Throwable e1) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
XContentLocation location = highlighterParser != null ? highlighterParser.getTokenLocation() : null;
|
XContentLocation location = highlighterParser != null ? highlighterParser.getTokenLocation() : null;
|
||||||
throw new SearchParseException(context, "failed to parse suggest source [" + sSource + "]", location, e);
|
throw new SearchParseException(context, "failed to parse suggest source [" + sSource + "]", location, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (source.innerHits() != null) {
|
if (source.innerHits() != null) {
|
||||||
XContentParser innerHitsParser = null;
|
XContentParser innerHitsParser = null;
|
||||||
|
@ -843,7 +844,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
this.elementParsers.get("inner_hits").parse(innerHitsParser, context);
|
this.elementParsers.get("inner_hits").parse(innerHitsParser, context);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String sSource = "_na_";
|
String sSource = "_na_";
|
||||||
try {
|
try {
|
||||||
sSource = source.toString();
|
sSource = source.toString();
|
||||||
} catch (Throwable e1) {
|
} catch (Throwable e1) {
|
||||||
// ignore
|
// ignore
|
||||||
|
@ -857,7 +858,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
SearchScript searchScript = context.scriptService().search(context.lookup(), field.script(), ScriptContext.Standard.SEARCH);
|
SearchScript searchScript = context.scriptService().search(context.lookup(), field.script(), ScriptContext.Standard.SEARCH);
|
||||||
context.scriptFields().add(new ScriptField(field.fieldName(), searchScript, field.ignoreFailure()));
|
context.scriptFields().add(new ScriptField(field.fieldName(), searchScript, field.ignoreFailure()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (source.ext() != null) {
|
if (source.ext() != null) {
|
||||||
XContentParser extParser = null;
|
XContentParser extParser = null;
|
||||||
try {
|
try {
|
||||||
|
@ -865,32 +866,32 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
XContentParser.Token token = extParser.nextToken();
|
XContentParser.Token token = extParser.nextToken();
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
while ((token = extParser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = extParser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
currentFieldName = extParser.currentName();
|
currentFieldName = extParser.currentName();
|
||||||
} else {
|
} else {
|
||||||
SearchParseElement parseElement = this.elementParsers.get(currentFieldName);
|
SearchParseElement parseElement = this.elementParsers.get(currentFieldName);
|
||||||
if (parseElement == null) {
|
if (parseElement == null) {
|
||||||
throw new SearchParseException(context, "Unknown element [" + currentFieldName + "] in [ext]",
|
throw new SearchParseException(context, "Unknown element [" + currentFieldName + "] in [ext]",
|
||||||
extParser.getTokenLocation());
|
extParser.getTokenLocation());
|
||||||
} else {
|
} else {
|
||||||
parseElement.parse(extParser, context);
|
parseElement.parse(extParser, context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String sSource = "_na_";
|
String sSource = "_na_";
|
||||||
try {
|
try {
|
||||||
sSource = source.toString();
|
sSource = source.toString();
|
||||||
} catch (Throwable e1) {
|
} catch (Throwable e1) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
XContentLocation location = extParser != null ? extParser.getTokenLocation() : null;
|
XContentLocation location = extParser != null ? extParser.getTokenLocation() : null;
|
||||||
throw new SearchParseException(context, "failed to parse ext source [" + sSource + "]", location, e);
|
throw new SearchParseException(context, "failed to parse ext source [" + sSource + "]", location, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (source.version() != null) {
|
if (source.version() != null) {
|
||||||
context.version(source.version());
|
context.version(source.version());
|
||||||
}
|
}
|
||||||
if (source.stats() != null) {
|
if (source.stats() != null) {
|
||||||
context.groupStats(source.stats());
|
context.groupStats(source.stats());
|
||||||
}
|
}
|
||||||
|
@ -1187,9 +1188,12 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
|
||||||
try {
|
try {
|
||||||
long now = System.nanoTime();
|
long now = System.nanoTime();
|
||||||
final IndexService indexService = indicesService.indexServiceSafe(indexShard.shardId().index().name());
|
final IndexService indexService = indicesService.indexServiceSafe(indexShard.shardId().index().name());
|
||||||
|
QueryParseContext queryParseContext = new QueryParseContext(indexService.queryParserService().indicesQueriesRegistry());
|
||||||
|
// NOCOMMIT get a parseFieldMatcher from somewhere and set it on the queryParseContext
|
||||||
|
queryParseContext.parseFieldMatcher(indexService.queryParserService().parseFieldMatcher());
|
||||||
ShardSearchRequest request = new ShardSearchLocalRequest(indexShard.shardId(), indexMetaData
|
ShardSearchRequest request = new ShardSearchLocalRequest(indexShard.shardId(), indexMetaData
|
||||||
.getNumberOfShards(),
|
.getNumberOfShards(),
|
||||||
SearchType.QUERY_THEN_FETCH, entry.source().build(new QueryParseContext(indexService.queryParserService().indicesQueriesRegistry())), entry.types(), entry.requestCache());
|
SearchType.QUERY_THEN_FETCH, entry.source().build(queryParseContext), entry.types(), entry.requestCache());
|
||||||
context = createContext(request, warmerContext.searcher());
|
context = createContext(request, warmerContext.searcher());
|
||||||
// if we use sort, we need to do query to sort on
|
// if we use sort, we need to do query to sort on
|
||||||
// it and load relevant field data
|
// it and load relevant field data
|
||||||
|
|
|
@ -20,18 +20,19 @@
|
||||||
package org.elasticsearch.action.search;
|
package org.elasticsearch.action.search;
|
||||||
|
|
||||||
import org.elasticsearch.action.support.IndicesOptions;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.query.MatchAllQueryParser;
|
import org.elasticsearch.index.query.MatchAllQueryParser;
|
||||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||||
import org.elasticsearch.rest.action.search.RestMultiSearchAction;
|
import org.elasticsearch.rest.action.search.RestMultiSearchAction;
|
||||||
import org.elasticsearch.script.ScriptService;
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.test.StreamsUtils;
|
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
import org.elasticsearch.test.StreamsUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -46,7 +47,8 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
public void simpleAdd() throws Exception {
|
public void simpleAdd() throws Exception {
|
||||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
||||||
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch1.json");
|
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch1.json");
|
||||||
MultiSearchRequest request = RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), false, null, null, null, null, IndicesOptions.strictExpandOpenAndForbidClosed(),true, registry);
|
MultiSearchRequest request = RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), false, null, null,
|
||||||
|
null, null, IndicesOptions.strictExpandOpenAndForbidClosed(), true, registry, ParseFieldMatcher.EMPTY);
|
||||||
assertThat(request.requests().size(), equalTo(8));
|
assertThat(request.requests().size(), equalTo(8));
|
||||||
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
|
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
|
||||||
assertThat(request.requests().get(0).indicesOptions(), equalTo(IndicesOptions.fromOptions(true, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
|
assertThat(request.requests().get(0).indicesOptions(), equalTo(IndicesOptions.fromOptions(true, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
|
||||||
|
@ -73,7 +75,8 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
public void simpleAdd2() throws Exception {
|
public void simpleAdd2() throws Exception {
|
||||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
||||||
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch2.json");
|
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch2.json");
|
||||||
MultiSearchRequest request =RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), false, null, null, null, null, IndicesOptions.strictExpandOpenAndForbidClosed(), true, registry);
|
MultiSearchRequest request = RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), false, null, null,
|
||||||
|
null, null, IndicesOptions.strictExpandOpenAndForbidClosed(), true, registry, ParseFieldMatcher.EMPTY);
|
||||||
assertThat(request.requests().size(), equalTo(5));
|
assertThat(request.requests().size(), equalTo(5));
|
||||||
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
|
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
|
||||||
assertThat(request.requests().get(0).types().length, equalTo(0));
|
assertThat(request.requests().get(0).types().length, equalTo(0));
|
||||||
|
@ -92,7 +95,8 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
public void simpleAdd3() throws Exception {
|
public void simpleAdd3() throws Exception {
|
||||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
||||||
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch3.json");
|
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch3.json");
|
||||||
MultiSearchRequest request =RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), false, null, null, null, null, IndicesOptions.strictExpandOpenAndForbidClosed(), true, registry);
|
MultiSearchRequest request = RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), false, null, null,
|
||||||
|
null, null, IndicesOptions.strictExpandOpenAndForbidClosed(), true, registry, ParseFieldMatcher.EMPTY);
|
||||||
assertThat(request.requests().size(), equalTo(4));
|
assertThat(request.requests().size(), equalTo(4));
|
||||||
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
||||||
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
||||||
|
@ -112,7 +116,8 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
public void simpleAdd4() throws Exception {
|
public void simpleAdd4() throws Exception {
|
||||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
||||||
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch4.json");
|
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch4.json");
|
||||||
MultiSearchRequest request = RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), false, null, null, null, null, IndicesOptions.strictExpandOpenAndForbidClosed(), true, registry);
|
MultiSearchRequest request = RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), false, null, null,
|
||||||
|
null, null, IndicesOptions.strictExpandOpenAndForbidClosed(), true, registry, ParseFieldMatcher.EMPTY);
|
||||||
assertThat(request.requests().size(), equalTo(3));
|
assertThat(request.requests().size(), equalTo(3));
|
||||||
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
||||||
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
||||||
|
@ -134,7 +139,8 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
public void simpleAdd5() throws Exception {
|
public void simpleAdd5() throws Exception {
|
||||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, Collections.singleton(new MatchAllQueryParser()), new NamedWriteableRegistry());
|
||||||
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch5.json");
|
byte[] data = StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/search/simple-msearch5.json");
|
||||||
MultiSearchRequest request = RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), true, null, null, null, null, IndicesOptions.strictExpandOpenAndForbidClosed(), true, registry);
|
MultiSearchRequest request = RestMultiSearchAction.parseRequest(new MultiSearchRequest(), new BytesArray(data), true, null, null,
|
||||||
|
null, null, IndicesOptions.strictExpandOpenAndForbidClosed(), true, registry, ParseFieldMatcher.EMPTY);
|
||||||
assertThat(request.requests().size(), equalTo(3));
|
assertThat(request.requests().size(), equalTo(3));
|
||||||
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
assertThat(request.requests().get(0).indices()[0], equalTo("test0"));
|
||||||
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
assertThat(request.requests().get(0).indices()[1], equalTo("test1"));
|
||||||
|
|
|
@ -209,7 +209,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
// TEST FETCHING _parent from child
|
// TEST FETCHING _parent from child
|
||||||
SearchResponse searchResponse = client().prepareSearch("test").setQuery(idsQuery("child").addIds("c1")).addFields("_parent").execute()
|
SearchResponse searchResponse = client().prepareSearch("test").setQuery(idsQuery("child").addIds("c1")).fields("_parent").execute()
|
||||||
.actionGet();
|
.actionGet();
|
||||||
assertNoFailures(searchResponse);
|
assertNoFailures(searchResponse);
|
||||||
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
||||||
|
@ -217,7 +217,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
||||||
assertThat(searchResponse.getHits().getAt(0).field("_parent").value().toString(), equalTo("p1"));
|
assertThat(searchResponse.getHits().getAt(0).field("_parent").value().toString(), equalTo("p1"));
|
||||||
|
|
||||||
// TEST matching on parent
|
// TEST matching on parent
|
||||||
searchResponse = client().prepareSearch("test").setQuery(termQuery("_parent", "p1")).addFields("_parent").get();
|
searchResponse = client().prepareSearch("test").setQuery(termQuery("_parent", "p1")).fields("_parent").get();
|
||||||
assertNoFailures(searchResponse);
|
assertNoFailures(searchResponse);
|
||||||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||||
assertThat(searchResponse.getHits().getAt(0).id(), anyOf(equalTo("c1"), equalTo("c2")));
|
assertThat(searchResponse.getHits().getAt(0).id(), anyOf(equalTo("c1"), equalTo("c2")));
|
||||||
|
@ -225,7 +225,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
||||||
assertThat(searchResponse.getHits().getAt(1).id(), anyOf(equalTo("c1"), equalTo("c2")));
|
assertThat(searchResponse.getHits().getAt(1).id(), anyOf(equalTo("c1"), equalTo("c2")));
|
||||||
assertThat(searchResponse.getHits().getAt(1).field("_parent").value().toString(), equalTo("p1"));
|
assertThat(searchResponse.getHits().getAt(1).field("_parent").value().toString(), equalTo("p1"));
|
||||||
|
|
||||||
searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("_parent:p1")).addFields("_parent").get();
|
searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("_parent:p1")).fields("_parent").get();
|
||||||
assertNoFailures(searchResponse);
|
assertNoFailures(searchResponse);
|
||||||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||||
assertThat(searchResponse.getHits().getAt(0).id(), anyOf(equalTo("c1"), equalTo("c2")));
|
assertThat(searchResponse.getHits().getAt(0).id(), anyOf(equalTo("c1"), equalTo("c2")));
|
||||||
|
|
|
@ -71,6 +71,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler {
|
||||||
XContentParser requestParser = XContentFactory.xContent(request.content()).createParser(request.content());
|
XContentParser requestParser = XContentFactory.xContent(request.content()).createParser(request.content());
|
||||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
||||||
context.reset(requestParser);
|
context.reset(requestParser);
|
||||||
|
context.parseFieldMatcher(parseFieldMatcher);
|
||||||
final QueryBuilder<?> builder = context.parseInnerQueryBuilder();
|
final QueryBuilder<?> builder = context.parseInnerQueryBuilder();
|
||||||
delete.query(builder);
|
delete.query(builder);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -197,7 +197,7 @@ public class TransportDeleteByQueryActionTests extends ESSingleNodeTestCase {
|
||||||
SearchResponse searchResponse = client().prepareSearch("test")
|
SearchResponse searchResponse = client().prepareSearch("test")
|
||||||
.setScroll(TimeValue.timeValueSeconds(10))
|
.setScroll(TimeValue.timeValueSeconds(10))
|
||||||
.setQuery(boolQuery().must(rangeQuery("num").lte(limit)))
|
.setQuery(boolQuery().must(rangeQuery("num").lte(limit)))
|
||||||
.addFields("_routing", "_parent")
|
.fields("_routing", "_parent")
|
||||||
.setFetchSource(false)
|
.setFetchSource(false)
|
||||||
.setVersion(true)
|
.setVersion(true)
|
||||||
.get();
|
.get();
|
||||||
|
|
Loading…
Reference in New Issue