remove ParseFieldMatcher usages from FetchSourceContext
This commit is contained in:
parent
dea7d65439
commit
723bdc4549
|
@ -349,7 +349,7 @@ public class BulkRequest extends ActionRequest implements CompositeIndicesReques
|
||||||
} else if ("fields".equals(currentFieldName)) {
|
} else if ("fields".equals(currentFieldName)) {
|
||||||
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains a simple value for parameter [fields] while a list is expected");
|
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains a simple value for parameter [fields] while a list is expected");
|
||||||
} else if ("_source".equals(currentFieldName)) {
|
} else if ("_source".equals(currentFieldName)) {
|
||||||
fetchSourceContext = FetchSourceContext.parse(parser);
|
fetchSourceContext = FetchSourceContext.fromXContent(parser);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + currentFieldName + "]");
|
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ public class BulkRequest extends ActionRequest implements CompositeIndicesReques
|
||||||
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
|
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
|
||||||
}
|
}
|
||||||
} else if (token == XContentParser.Token.START_OBJECT && "_source".equals(currentFieldName)) {
|
} else if (token == XContentParser.Token.START_OBJECT && "_source".equals(currentFieldName)) {
|
||||||
fetchSourceContext = FetchSourceContext.parse(parser);
|
fetchSourceContext = FetchSourceContext.fromXContent(parser);
|
||||||
} else if (token != XContentParser.Token.VALUE_NULL) {
|
} else if (token != XContentParser.Token.VALUE_NULL) {
|
||||||
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
|
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
|
||||||
}
|
}
|
||||||
|
|
|
@ -739,7 +739,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||||
fields(fields.toArray(new String[fields.size()]));
|
fields(fields.toArray(new String[fields.size()]));
|
||||||
}
|
}
|
||||||
} else if ("_source".equals(currentFieldName)) {
|
} else if ("_source".equals(currentFieldName)) {
|
||||||
fetchSourceContext = FetchSourceContext.parse(parser);
|
fetchSourceContext = FetchSourceContext.fromXContent(parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (script != null) {
|
if (script != null) {
|
||||||
|
|
|
@ -96,7 +96,7 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
|
||||||
ObjectParser.ValueType.OBJECT_ARRAY);
|
ObjectParser.ValueType.OBJECT_ARRAY);
|
||||||
PARSER.declareField((p, i, c) -> {
|
PARSER.declareField((p, i, c) -> {
|
||||||
try {
|
try {
|
||||||
i.setFetchSourceContext(FetchSourceContext.parse(c.parser()));
|
i.setFetchSourceContext(FetchSourceContext.fromXContent(c.parser()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ParsingException(p.getTokenLocation(), "Could not parse inner _source definition", e);
|
throw new ParsingException(p.getTokenLocation(), "Could not parse inner _source definition", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -616,7 +616,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit
|
||||||
} else if (SearchSourceBuilder.TRACK_SCORES_FIELD.match(currentFieldName)) {
|
} else if (SearchSourceBuilder.TRACK_SCORES_FIELD.match(currentFieldName)) {
|
||||||
factory.trackScores(parser.booleanValue());
|
factory.trackScores(parser.booleanValue());
|
||||||
} else if (SearchSourceBuilder._SOURCE_FIELD.match(currentFieldName)) {
|
} else if (SearchSourceBuilder._SOURCE_FIELD.match(currentFieldName)) {
|
||||||
factory.fetchSource(FetchSourceContext.parse(context.parser()));
|
factory.fetchSource(FetchSourceContext.fromXContent(context.parser()));
|
||||||
} else if (SearchSourceBuilder.STORED_FIELDS_FIELD.match(currentFieldName)) {
|
} else if (SearchSourceBuilder.STORED_FIELDS_FIELD.match(currentFieldName)) {
|
||||||
factory.storedFieldsContext =
|
factory.storedFieldsContext =
|
||||||
StoredFieldsContext.fromXContent(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), context);
|
StoredFieldsContext.fromXContent(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), context);
|
||||||
|
@ -628,7 +628,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit
|
||||||
}
|
}
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
if (SearchSourceBuilder._SOURCE_FIELD.match(currentFieldName)) {
|
if (SearchSourceBuilder._SOURCE_FIELD.match(currentFieldName)) {
|
||||||
factory.fetchSource(FetchSourceContext.parse(context.parser()));
|
factory.fetchSource(FetchSourceContext.fromXContent(context.parser()));
|
||||||
} else if (SearchSourceBuilder.SCRIPT_FIELDS_FIELD.match(currentFieldName)) {
|
} else if (SearchSourceBuilder.SCRIPT_FIELDS_FIELD.match(currentFieldName)) {
|
||||||
List<ScriptField> scriptFields = new ArrayList<>();
|
List<ScriptField> scriptFields = new ArrayList<>();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
|
@ -699,7 +699,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit
|
||||||
List<SortBuilder<?>> sorts = SortBuilder.fromXContent(context);
|
List<SortBuilder<?>> sorts = SortBuilder.fromXContent(context);
|
||||||
factory.sorts(sorts);
|
factory.sorts(sorts);
|
||||||
} else if (SearchSourceBuilder._SOURCE_FIELD.match(currentFieldName)) {
|
} else if (SearchSourceBuilder._SOURCE_FIELD.match(currentFieldName)) {
|
||||||
factory.fetchSource(FetchSourceContext.parse(context.parser()));
|
factory.fetchSource(FetchSourceContext.fromXContent(context.parser()));
|
||||||
} else {
|
} else {
|
||||||
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].",
|
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].",
|
||||||
parser.getTokenLocation());
|
parser.getTokenLocation());
|
||||||
|
|
|
@ -948,7 +948,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
|
||||||
} else if (TRACK_SCORES_FIELD.match(currentFieldName)) {
|
} else if (TRACK_SCORES_FIELD.match(currentFieldName)) {
|
||||||
trackScores = parser.booleanValue();
|
trackScores = parser.booleanValue();
|
||||||
} else if (_SOURCE_FIELD.match(currentFieldName)) {
|
} else if (_SOURCE_FIELD.match(currentFieldName)) {
|
||||||
fetchSourceContext = FetchSourceContext.parse(context.parser());
|
fetchSourceContext = FetchSourceContext.fromXContent(context.parser());
|
||||||
} else if (STORED_FIELDS_FIELD.match(currentFieldName)) {
|
} else if (STORED_FIELDS_FIELD.match(currentFieldName)) {
|
||||||
storedFieldsContext =
|
storedFieldsContext =
|
||||||
StoredFieldsContext.fromXContent(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), context);
|
StoredFieldsContext.fromXContent(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), context);
|
||||||
|
@ -970,7 +970,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
|
||||||
} else if (POST_FILTER_FIELD.match(currentFieldName)) {
|
} else if (POST_FILTER_FIELD.match(currentFieldName)) {
|
||||||
postQueryBuilder = context.parseInnerQueryBuilder();
|
postQueryBuilder = context.parseInnerQueryBuilder();
|
||||||
} else if (_SOURCE_FIELD.match(currentFieldName)) {
|
} else if (_SOURCE_FIELD.match(currentFieldName)) {
|
||||||
fetchSourceContext = FetchSourceContext.parse(context.parser());
|
fetchSourceContext = FetchSourceContext.fromXContent(context.parser());
|
||||||
} else if (SCRIPT_FIELDS_FIELD.match(currentFieldName)) {
|
} else if (SCRIPT_FIELDS_FIELD.match(currentFieldName)) {
|
||||||
scriptFields = new ArrayList<>();
|
scriptFields = new ArrayList<>();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
|
@ -1059,7 +1059,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (_SOURCE_FIELD.match(currentFieldName)) {
|
} else if (_SOURCE_FIELD.match(currentFieldName)) {
|
||||||
fetchSourceContext = FetchSourceContext.parse(context.parser());
|
fetchSourceContext = FetchSourceContext.fromXContent(context.parser());
|
||||||
} else if (SEARCH_AFTER.match(currentFieldName)) {
|
} else if (SEARCH_AFTER.match(currentFieldName)) {
|
||||||
searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.getParseFieldMatcher());
|
searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.getParseFieldMatcher());
|
||||||
} else if (FIELDS_FIELD.match(currentFieldName)) {
|
} else if (FIELDS_FIELD.match(currentFieldName)) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.search.fetch.subphase;
|
||||||
|
|
||||||
import org.elasticsearch.common.Booleans;
|
import org.elasticsearch.common.Booleans;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -55,10 +54,6 @@ public class FetchSourceContext implements Writeable, ToXContent {
|
||||||
private final String[] excludes;
|
private final String[] excludes;
|
||||||
private Function<Map<String, ?>, Map<String, Object>> filter;
|
private Function<Map<String, ?>, Map<String, Object>> filter;
|
||||||
|
|
||||||
public static FetchSourceContext parse(XContentParser parser) throws IOException {
|
|
||||||
return fromXContent(parser, ParseFieldMatcher.STRICT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FetchSourceContext(boolean fetchSource, String[] includes, String[] excludes) {
|
public FetchSourceContext(boolean fetchSource, String[] includes, String[] excludes) {
|
||||||
this.fetchSource = fetchSource;
|
this.fetchSource = fetchSource;
|
||||||
this.includes = includes == null ? Strings.EMPTY_ARRAY : includes;
|
this.includes = includes == null ? Strings.EMPTY_ARRAY : includes;
|
||||||
|
@ -127,7 +122,7 @@ public class FetchSourceContext implements Writeable, ToXContent {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FetchSourceContext fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException {
|
public static FetchSourceContext fromXContent(XContentParser parser) throws IOException {
|
||||||
XContentParser.Token token = parser.currentToken();
|
XContentParser.Token token = parser.currentToken();
|
||||||
boolean fetchSource = true;
|
boolean fetchSource = true;
|
||||||
String[] includes = Strings.EMPTY_ARRAY;
|
String[] includes = Strings.EMPTY_ARRAY;
|
||||||
|
|
Loading…
Reference in New Issue