diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java index a812cb22eb6..d31d0c9ae14 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java @@ -27,7 +27,6 @@ import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.action.support.replication.ReplicationRequest; import org.elasticsearch.action.support.single.instance.InstanceShardOperationRequest; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.logging.DeprecationLogger; @@ -714,7 +713,7 @@ public class UpdateRequest extends InstanceShardOperationRequest if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if ("script".equals(currentFieldName)) { - script = Script.parse(parser, ParseFieldMatcher.EMPTY); + script = Script.parse(parser); } else if ("scripted_upsert".equals(currentFieldName)) { scriptedUpsert = parser.booleanValue(); } else if ("upsert".equals(currentFieldName)) { diff --git a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java index 077a687ed83..526fc2b69ce 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java @@ -100,7 +100,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder // skip } else if (token == XContentParser.Token.START_OBJECT) { if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, parseContext.getParseFieldMatcher(), parseContext.getDefaultScriptLanguage()); + script = Script.parse(parser, parseContext.getDefaultScriptLanguage()); } else { throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]"); } @@ -110,7 +110,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) { boost = parser.floatValue(); } else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, parseContext.getParseFieldMatcher(), parseContext.getDefaultScriptLanguage()); + script = Script.parse(parser, parseContext.getDefaultScriptLanguage()); } else { throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]"); } diff --git a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java index b1fee2d6252..68913cd9e21 100644 --- a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java @@ -112,7 +112,7 @@ public class ScriptScoreFunctionBuilder extends ScoreFunctionBuilder PARSER = new ObjectParser<>("script", Builder::new); + private static final ObjectParser PARSER = new ObjectParser<>("script", Builder::new); static { // Defines the fields necessary to parse a Script as XContent using an ObjectParser. @@ -224,19 +221,11 @@ public final class Script implements ToXContent, Writeable { } /** - * Convenience method to call {@link Script#parse(XContentParser, ParseFieldMatcher, String)} + * Convenience method to call {@link Script#parse(XContentParser, String)} * using the default scripting language. */ - public static Script parse(XContentParser parser, ParseFieldMatcher matcher) throws IOException { - return parse(parser, matcher, DEFAULT_SCRIPT_LANG); - } - - /** - * Convenience method to call {@link Script#parse(XContentParser, ParseFieldMatcher, String)} using the - * {@link ParseFieldMatcher} and scripting language provided by the {@link QueryParseContext}. - */ - public static Script parse(XContentParser parser, QueryParseContext context) throws IOException { - return parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + public static Script parse(XContentParser parser) throws IOException { + return parse(parser, DEFAULT_SCRIPT_LANG); } /** @@ -300,13 +289,12 @@ public final class Script implements ToXContent, Writeable { * } * * @param parser The {@link XContentParser} to be used. - * @param matcher The {@link ParseFieldMatcher} to be used. * @param defaultLang The default language to use if no language is specified. The default language isn't necessarily * the one defined by {@link Script#DEFAULT_SCRIPT_LANG} due to backwards compatiblity requirements * related to stored queries using previously default languauges. * @return The parsed {@link Script}. */ - public static Script parse(XContentParser parser, ParseFieldMatcher matcher, String defaultLang) throws IOException { + public static Script parse(XContentParser parser, String defaultLang) throws IOException { Objects.requireNonNull(defaultLang); Token token = parser.currentToken(); @@ -319,7 +307,7 @@ public final class Script implements ToXContent, Writeable { return new Script(ScriptType.INLINE, defaultLang, parser.text(), Collections.emptyMap()); } - return PARSER.apply(parser, () -> matcher).build(defaultLang); + return PARSER.apply(parser, null).build(defaultLang); } private final ScriptType type; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java index b49ca9fe1c9..083733f31ae 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/ScriptHeuristic.java @@ -158,7 +158,7 @@ public class ScriptHeuristic extends SignificanceHeuristic { currentFieldName = parser.currentName(); } else { if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else { throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown object [{}]", heuristicName, currentFieldName); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java index 6b4d1bc1b8f..68a5138271f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregationBuilder.java @@ -38,7 +38,6 @@ import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; -import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Objects; @@ -255,13 +254,13 @@ public class ScriptedMetricAggregationBuilder extends AbstractAggregationBuilder currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.VALUE_STRING) { if (INIT_SCRIPT_FIELD.match(currentFieldName)) { - initScript = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + initScript = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (MAP_SCRIPT_FIELD.match(currentFieldName)) { - mapScript = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + mapScript = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (COMBINE_SCRIPT_FIELD.match(currentFieldName)) { - combineScript = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + combineScript = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (REDUCE_SCRIPT_FIELD.match(currentFieldName)) { - reduceScript = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + reduceScript = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (token == XContentParser.Token.START_OBJECT && PARAMS_FIELD.match(currentFieldName)) { params = parser.map(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java index 7cfc0cf61c1..978060632dc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java @@ -642,7 +642,7 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder map = parser.map(); bucketsPathsMap = new HashMap<>(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java index 8a88f011756..078f50a978f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java @@ -141,7 +141,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg } else if (GAP_POLICY.match(currentFieldName)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); } else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); @@ -163,7 +163,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg } } else if (token == XContentParser.Token.START_OBJECT) { if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (BUCKETS_PATH.match(currentFieldName)) { Map map = parser.map(); bucketsPathsMap = new HashMap<>(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceParserHelper.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceParserHelper.java index 2af21192a44..7b174d789f4 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceParserHelper.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceParserHelper.java @@ -35,30 +35,30 @@ public final class ValuesSourceParserHelper { public static void declareAnyFields( ObjectParser, QueryParseContext> objectParser, boolean scriptable, boolean formattable) { - declareFields(objectParser, scriptable, formattable, false, ValuesSourceType.ANY, null); + declareFields(objectParser, scriptable, formattable, false, null); } public static void declareNumericFields( ObjectParser, QueryParseContext> objectParser, boolean scriptable, boolean formattable, boolean timezoneAware) { - declareFields(objectParser, scriptable, formattable, timezoneAware, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + declareFields(objectParser, scriptable, formattable, timezoneAware, ValueType.NUMERIC); } public static void declareBytesFields( ObjectParser, QueryParseContext> objectParser, boolean scriptable, boolean formattable) { - declareFields(objectParser, scriptable, formattable, false, ValuesSourceType.BYTES, ValueType.STRING); + declareFields(objectParser, scriptable, formattable, false, ValueType.STRING); } public static void declareGeoFields( ObjectParser, QueryParseContext> objectParser, boolean scriptable, boolean formattable) { - declareFields(objectParser, scriptable, formattable, false, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); + declareFields(objectParser, scriptable, formattable, false, ValueType.GEOPOINT); } private static void declareFields( ObjectParser, QueryParseContext> objectParser, - boolean scriptable, boolean formattable, boolean timezoneAware, ValuesSourceType valuesSourceType, ValueType targetValueType) { + boolean scriptable, boolean formattable, boolean timezoneAware, ValueType targetValueType) { objectParser.declareField(ValuesSourceAggregationBuilder::field, XContentParser::text, @@ -84,7 +84,8 @@ public final class ValuesSourceParserHelper { } if (scriptable) { - objectParser.declareField(ValuesSourceAggregationBuilder::script, org.elasticsearch.script.Script::parse, + objectParser.declareField(ValuesSourceAggregationBuilder::script, + (parser, context) -> Script.parse(parser, context.getDefaultScriptLanguage()), Script.SCRIPT_PARSE_FIELD, ObjectParser.ValueType.OBJECT_OR_STRING); } diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 7ecd06c8c83..35c6488136b 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -1341,7 +1341,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ currentFieldName = parser.currentName(); } else if (token.isValue()) { if (SCRIPT_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else if (IGNORE_FAILURE_FIELD.match(currentFieldName)) { ignoreFailure = parser.booleanValue(); } else { @@ -1350,7 +1350,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } } else if (token == XContentParser.Token.START_OBJECT) { if (SCRIPT_FIELD.match(currentFieldName)) { - script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage()); + script = Script.parse(parser, context.getDefaultScriptLanguage()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java index 6da93b26b8c..f284597e782 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java @@ -216,7 +216,8 @@ public class ScriptSortBuilder extends SortBuilder { a -> new ScriptSortBuilder((Script) a[0], (ScriptSortType) a[1])); static { - PARSER.declareField(constructorArg(), Script::parse, Script.SCRIPT_PARSE_FIELD, ValueType.OBJECT_OR_STRING); + PARSER.declareField(constructorArg(), (parser, context) -> Script.parse(parser, context.getDefaultScriptLanguage()), + Script.SCRIPT_PARSE_FIELD, ValueType.OBJECT_OR_STRING); PARSER.declareField(constructorArg(), p -> ScriptSortType.fromString(p.text()), TYPE_FIELD, ValueType.STRING); PARSER.declareString((b, v) -> b.order(SortOrder.fromString(v)), ORDER_FIELD); PARSER.declareString((b, v) -> b.sortMode(SortMode.fromString(v)), SORTMODE_FIELD); diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java index 20d4f6853c0..12d2af289a9 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java @@ -567,7 +567,7 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder s.versionType(VersionType.fromString(i)), new ParseField("version_type")); - PARSER.declareField((p, v, c) -> sourceParser.parse(p, v, c), new ParseField("source"), ValueType.OBJECT); + PARSER.declareField(sourceParser::parse, new ParseField("source"), ValueType.OBJECT); PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), c), new ParseField("dest"), ValueType.OBJECT); PARSER.declareInt(ReindexRequest::setSize, new ParseField("size")); - PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.getParseFieldMatcher())), new ParseField("script"), + PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p)), new ParseField("script"), ValueType.OBJECT); PARSER.declareString(ReindexRequest::setConflicts, new ParseField("conflicts")); }