From 15c59d07b325c3e72dd0e8fc90cc0811285efff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Thu, 14 Apr 2016 15:47:03 +0200 Subject: [PATCH 1/2] Remove ParseFieldMatcher from AbstractXContentParser Currently we are able to set a ParseFieldMatcher on XContentParsers, mainly to conveniently carry it around to be available where the actual parsing happens. This was just recently introduced together with ObjectParser so that ObjectParser can make use of deprecation logging and throwing errors while parsing. This however is trappy because we create parsers in so many places in the code and it is easy to forget setting the right ParseFieldMatcher. Instead we should hold the ParseFieldMatcher only in the parse contexts (e.g. QueryParseContext). This PR removes the ParseFieldMatcher from XContentParser. ObjectParser can still make use of it because we can make the otherwise unbounded `context` type to extend an interface that makes sure contexts used in ObjectParser can supply a ParseFieldMatcher. Contexts in ObjectParser are now no longer optional, but it is sufficient to pass in a small lambda expression in places where no other context is available. Relates to #17417 --- .../ClusterAllocationExplainRequest.java | 9 +- .../reroute/ClusterRerouteRequest.java | 6 +- .../cluster/routing/AllocationId.java | 7 +- .../AbstractAllocateAllocationCommand.java | 5 +- ...AllocateEmptyPrimaryAllocationCommand.java | 7 +- .../AllocateReplicaAllocationCommand.java | 7 +- ...AllocateStalePrimaryAllocationCommand.java | 7 +- .../command/AllocationCommands.java | 6 +- .../command/BasePrimaryAllocationCommand.java | 5 +- .../common/ParseFieldMatcherSupplier.java | 36 +++++++ .../common/xcontent/ObjectParser.java | 23 ++--- .../common/xcontent/ParseFieldRegistry.java | 14 +-- .../common/xcontent/XContentParser.java | 16 +-- .../support/AbstractXContentParser.java | 11 --- .../index/query/QueryParseContext.java | 12 +-- .../index/query/QueryShardContext.java | 5 +- .../FunctionScoreQueryBuilder.java | 6 +- .../elasticsearch/ingest/IngestMetadata.java | 7 +- .../ingest/PipelineConfiguration.java | 6 +- .../aggregations/AggregatorParsers.java | 18 ++-- .../CompletionSuggestionBuilder.java | 10 +- .../suggest/completion/FuzzyOptions.java | 8 +- .../suggest/completion/RegexOptions.java | 8 +- .../context/CategoryQueryContext.java | 6 +- .../completion/context/GeoQueryContext.java | 6 +- .../DirectCandidateGeneratorBuilder.java | 4 +- .../allocation/AllocationCommandsTests.java | 3 +- .../common/xcontent/ObjectParserTests.java | 99 ++++++++++--------- .../search/SearchModuleTests.java | 8 +- .../aggregations/BaseAggregationTestCase.java | 2 +- .../BasePipelineAggregationTestCase.java | 2 +- .../pipeline/moving/avg/MovAvgTests.java | 5 +- .../search/sort/SortParserTests.java | 40 ++++++-- .../index/reindex/RestReindexAction.java | 13 ++- 34 files changed, 245 insertions(+), 182 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java index 11722821efb..4d143c437c3 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java @@ -24,14 +24,14 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeRequest; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.Strings; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; -import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -40,7 +40,8 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; */ public class ClusterAllocationExplainRequest extends MasterNodeRequest { - private static ObjectParser PARSER = new ObjectParser("cluster/allocation/explain"); + private static ObjectParser PARSER = new ObjectParser( + "cluster/allocation/explain"); static { PARSER.declareString(ClusterAllocationExplainRequest::setIndex, new ParseField("index")); PARSER.declareInt(ClusterAllocationExplainRequest::setShard, new ParseField("shard")); @@ -148,7 +149,7 @@ public class ClusterAllocationExplainRequest extends MasterNodeRequest ParseFieldMatcher.STRICT); Exception e = req.validate(); if (e != null) { throw new ElasticsearchParseException("'index', 'shard', and 'primary' must be specified in allocation explain request", e); diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java index fc371b9c1f0..a241f01ea28 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java @@ -25,17 +25,14 @@ import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.cluster.routing.allocation.command.AllocationCommand; import org.elasticsearch.cluster.routing.allocation.command.AllocationCommandRegistry; import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands; -import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; -import java.util.List; /** * Request to submit cluster reroute allocation commands @@ -105,7 +102,6 @@ public class ClusterRerouteRequest extends AcknowledgedRequest ALLOCATION_ID_PARSER = new ObjectParser<>("allocationId"); + private static final ObjectParser ALLOCATION_ID_PARSER = new ObjectParser<>( + "allocationId"); static { ALLOCATION_ID_PARSER.declareString(AllocationId.Builder::setId, new ParseField(ID_KEY)); @@ -198,6 +201,6 @@ public class AllocationId implements ToXContent { } public static AllocationId fromXContent(XContentParser parser) throws IOException { - return ALLOCATION_ID_PARSER.parse(parser, new AllocationId.Builder()).build(); + return ALLOCATION_ID_PARSER.parse(parser, new AllocationId.Builder(), () -> ParseFieldMatcher.STRICT).build(); } } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java index 28a829b5af9..50e71c5094a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java @@ -28,6 +28,7 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; @@ -47,8 +48,8 @@ public abstract class AbstractAllocateAllocationCommand implements AllocationCom private static final String SHARD_FIELD = "shard"; private static final String NODE_FIELD = "node"; - protected static > ObjectParser createAllocateParser(String command) { - ObjectParser parser = new ObjectParser<>(command); + protected static > ObjectParser createAllocateParser(String command) { + ObjectParser parser = new ObjectParser<>(command); parser.declareString(Builder::setIndex, new ParseField(INDEX_FIELD)); parser.declareInt(Builder::setShard, new ParseField(SHARD_FIELD)); parser.declareString(Builder::setNode, new ParseField(NODE_FIELD)); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java index 4ee0294faaf..74e3a18efbc 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java @@ -28,6 +28,8 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -45,7 +47,8 @@ public class AllocateEmptyPrimaryAllocationCommand extends BasePrimaryAllocation public static final String NAME = "allocate_empty_primary"; public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME); - private static final ObjectParser EMPTY_PRIMARY_PARSER = BasePrimaryAllocationCommand.createAllocatePrimaryParser(NAME); + private static final ObjectParser EMPTY_PRIMARY_PARSER = BasePrimaryAllocationCommand + .createAllocatePrimaryParser(NAME); /** * Creates a new {@link AllocateEmptyPrimaryAllocationCommand} @@ -78,7 +81,7 @@ public class AllocateEmptyPrimaryAllocationCommand extends BasePrimaryAllocation @Override public Builder parse(XContentParser parser) throws IOException { - return EMPTY_PRIMARY_PARSER.parse(parser, this); + return EMPTY_PRIMARY_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java index a62928fded4..b651580ea74 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java @@ -28,6 +28,8 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -44,7 +46,8 @@ public class AllocateReplicaAllocationCommand extends AbstractAllocateAllocation public static final String NAME = "allocate_replica"; public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME); - private static final ObjectParser REPLICA_PARSER = createAllocateParser(NAME); + private static final ObjectParser REPLICA_PARSER = + createAllocateParser(NAME); /** * Creates a new {@link AllocateReplicaAllocationCommand} @@ -77,7 +80,7 @@ public class AllocateReplicaAllocationCommand extends AbstractAllocateAllocation @Override public Builder parse(XContentParser parser) throws IOException { - return REPLICA_PARSER.parse(parser, this); + return REPLICA_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java index 438827d004e..5fad78d0360 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java @@ -28,6 +28,8 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -44,7 +46,8 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation public static final String NAME = "allocate_stale_primary"; public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME); - private static final ObjectParser STALE_PRIMARY_PARSER = BasePrimaryAllocationCommand.createAllocatePrimaryParser(NAME); + private static final ObjectParser STALE_PRIMARY_PARSER = BasePrimaryAllocationCommand + .createAllocatePrimaryParser(NAME); /** * Creates a new {@link AllocateStalePrimaryAllocationCommand} @@ -78,7 +81,7 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation @Override public Builder parse(XContentParser parser) throws IOException { - return STALE_PRIMARY_PARSER.parse(parser, this); + return STALE_PRIMARY_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocationCommands.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocationCommands.java index f5a06fe78a9..10c43fac7d7 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocationCommands.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocationCommands.java @@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation.command; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.RoutingExplanations; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; @@ -128,7 +129,8 @@ public class AllocationCommands { * @return {@link AllocationCommands} read * @throws IOException if something bad happens while reading the stream */ - public static AllocationCommands fromXContent(XContentParser parser, AllocationCommandRegistry registry) throws IOException { + public static AllocationCommands fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher, + AllocationCommandRegistry registry) throws IOException { AllocationCommands commands = new AllocationCommands(); XContentParser.Token token = parser.currentToken(); @@ -157,7 +159,7 @@ public class AllocationCommands { token = parser.nextToken(); String commandName = parser.currentName(); token = parser.nextToken(); - commands.add(registry.lookup(commandName, parser).fromXContent(parser)); + commands.add(registry.lookup(commandName, parser, parseFieldMatcher).fromXContent(parser)); // move to the end object one if (parser.nextToken() != XContentParser.Token.END_OBJECT) { throw new ElasticsearchParseException("allocation command is malformed, done parsing a command, but didn't get END_OBJECT, got [{}] instead", token); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java index bbb911c6f01..0013061e8ea 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster.routing.allocation.command; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; @@ -34,8 +35,8 @@ public abstract class BasePrimaryAllocationCommand extends AbstractAllocateAlloc private static final String ACCEPT_DATA_LOSS_FIELD = "accept_data_loss"; - protected static > ObjectParser createAllocatePrimaryParser(String command) { - ObjectParser parser = AbstractAllocateAllocationCommand.createAllocateParser(command); + protected static > ObjectParser createAllocatePrimaryParser(String command) { + ObjectParser parser = AbstractAllocateAllocationCommand.createAllocateParser(command); parser.declareBoolean(Builder::setAcceptDataLoss, new ParseField(ACCEPT_DATA_LOSS_FIELD)); return parser; } diff --git a/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java b/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java new file mode 100644 index 00000000000..b2b7b51ffcb --- /dev/null +++ b/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java @@ -0,0 +1,36 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common; + +import org.elasticsearch.index.query.QueryParseContext; +import org.elasticsearch.index.query.QueryShardContext; + +/** + * This interface should be implemented by classes like {@link QueryParseContext} or {@link QueryShardContext} that + * are able to carry a {@link ParseFieldMatcher}. + */ +@FunctionalInterface +public interface ParseFieldMatcherSupplier { + + /** + * @return the parseFieldMatcher + */ + ParseFieldMatcher parseFieldMatcher(); +} diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java index 311b93744ed..a9f6518211c 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java @@ -20,6 +20,7 @@ package org.elasticsearch.common.xcontent; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import java.io.IOException; @@ -51,7 +52,7 @@ import static org.elasticsearch.common.xcontent.XContentParser.Token.VALUE_STRIN * use the high level declare methods like {@link #declareString(BiConsumer, ParseField)} instead of {@link #declareField} which can be used * to implement exceptional parsing operations not covered by the high level methods. */ -public final class ObjectParser implements BiFunction { +public final class ObjectParser implements BiFunction { /** * Adapts an array (or varags) setter into a list setter. */ @@ -87,32 +88,22 @@ public final class ObjectParser implements BiFunction implements BiFunction { * Lookup a value from the registry by name while checking that the name matches the ParseField. * * @param name The name of the thing to look up. - * @param parser The parser from which the name was looked up. This is used to resolve the {@link ParseFieldMatcher} and to build nice - * error messages. + * @param parser The parser from which the name was looked up. + * @param parseFieldMatcher to build nice error messages. * @return The value being looked up. Never null. * @throws ParsingException if the named thing isn't in the registry or the name was deprecated and deprecated names aren't supported. */ - public T lookup(String name, XContentParser parser) { - T value = lookupReturningNullIfNotFound(name, parser); + public T lookup(String name, XContentParser parser, ParseFieldMatcher parseFieldMatcher) { + T value = lookupReturningNullIfNotFound(name, parseFieldMatcher); if (value == null) { throw new ParsingException(parser.getTokenLocation(), "no [" + registryName + "] registered for [" + name + "]"); } @@ -85,19 +85,19 @@ public class ParseFieldRegistry { * Lookup a value from the registry by name while checking that the name matches the ParseField. * * @param name The name of the thing to look up. - * @param parser The parser from which the name was looked up. This is used to resolve the {@link ParseFieldMatcher} and to build nice + * @param parseFieldMatcher The parseFieldMatcher. This is used to resolve the {@link ParseFieldMatcher} and to build nice * error messages. * @return The value being looked up or null if it wasn't found. * @throws ParsingException if the named thing isn't in the registry or the name was deprecated and deprecated names aren't supported. */ - public T lookupReturningNullIfNotFound(String name, XContentParser parser) { + public T lookupReturningNullIfNotFound(String name, ParseFieldMatcher parseFieldMatcher) { Tuple parseFieldAndValue = registry.get(name); if (parseFieldAndValue == null) { return null; } ParseField parseField = parseFieldAndValue.v1(); T value = parseFieldAndValue.v2(); - boolean match = parser.getParseFieldMatcher().match(name, parseField); + boolean match = parseFieldMatcher.match(name, parseField); //this is always expected to match, ParseField is useful for deprecation warnings etc. here assert match : "ParseField did not match registered name [" + name + "][" + registryName + "]"; return value; diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java index d647c5f0134..54de31c3150 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java @@ -20,7 +20,6 @@ package org.elasticsearch.common.xcontent; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.lease.Releasable; import java.io.IOException; @@ -187,7 +186,7 @@ public interface XContentParser extends Releasable { float floatValue(boolean coerce) throws IOException; double doubleValue(boolean coerce) throws IOException; - + short shortValue() throws IOException; int intValue() throws IOException; @@ -241,21 +240,10 @@ public interface XContentParser extends Releasable { /** * Used for error reporting to highlight where syntax errors occur in * content being parsed. - * + * * @return last token's location or null if cannot be determined */ XContentLocation getTokenLocation(); boolean isClosed(); - - /** - * Returns this parsers {@link ParseFieldMatcher} - */ - ParseFieldMatcher getParseFieldMatcher(); - - - /** - * Sets this parsers {@link ParseFieldMatcher} - */ - void setParseFieldMatcher(ParseFieldMatcher matcher) ; } diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java index e994b81832f..39a6fca1095 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java @@ -22,7 +22,6 @@ package org.elasticsearch.common.xcontent.support; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Booleans; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; @@ -37,8 +36,6 @@ import java.util.Map; */ public abstract class AbstractXContentParser implements XContentParser { - private ParseFieldMatcher matcher = ParseFieldMatcher.STRICT; - // Currently this is not a setting that can be changed and is a policy // that relates to how parsing of things like "boost" are done across // the whole of Elasticsearch (eg if String "1.0" is a valid float). @@ -337,12 +334,4 @@ public abstract class AbstractXContentParser implements XContentParser { @Override public abstract boolean isClosed(); - - public ParseFieldMatcher getParseFieldMatcher() { - return matcher; - } - - public void setParseFieldMatcher(ParseFieldMatcher matcher) { - this.matcher = matcher; - } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index 3fe7cfd6da5..ee6c49234fd 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -21,13 +21,14 @@ package org.elasticsearch.index.query; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import java.io.IOException; -public class QueryParseContext { +public class QueryParseContext implements ParseFieldMatcherSupplier { private static final ParseField CACHE = new ParseField("_cache").withAllDeprecated("Elasticsearch makes its own caching decisions"); private static final ParseField CACHE_KEY = new ParseField("_cache_key").withAllDeprecated("Filters are always used as cache keys"); @@ -44,9 +45,6 @@ public class QueryParseContext { public void reset(XContentParser jp) { this.parseFieldMatcher = ParseFieldMatcher.EMPTY; this.parser = jp; - if (parser != null) { - this.parser.setParseFieldMatcher(parseFieldMatcher); - } } public XContentParser parser() { @@ -57,9 +55,6 @@ public class QueryParseContext { if (parseFieldMatcher == null) { throw new IllegalArgumentException("parseFieldMatcher must not be null"); } - if (parser != null) { - parser.setParseFieldMatcher(parseFieldMatcher); - } this.parseFieldMatcher = parseFieldMatcher; } @@ -120,7 +115,7 @@ public class QueryParseContext { if (token != XContentParser.Token.START_OBJECT && token != XContentParser.Token.START_ARRAY) { throw new ParsingException(parser.getTokenLocation(), "[_na] query malformed, no field after start_object"); } - QueryBuilder result = indicesQueriesRegistry.lookup(queryName, parser).fromXContent(this); + QueryBuilder result = indicesQueriesRegistry.lookup(queryName, parser, parseFieldMatcher).fromXContent(this); if (parser.currentToken() == XContentParser.Token.END_OBJECT || parser.currentToken() == XContentParser.Token.END_ARRAY) { // if we are at END_OBJECT, move to the next one... parser.nextToken(); @@ -128,6 +123,7 @@ public class QueryParseContext { return result; } + @Override public ParseFieldMatcher parseFieldMatcher() { return parseFieldMatcher; } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java index b516e44ea28..6420c235c2e 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -29,6 +29,7 @@ import org.apache.lucene.search.similarities.Similarity; import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -49,7 +50,6 @@ import org.elasticsearch.index.mapper.core.TextFieldMapper; import org.elasticsearch.index.mapper.object.ObjectMapper; import org.elasticsearch.index.percolator.PercolatorQueryCache; import org.elasticsearch.index.query.support.InnerHitBuilder; -import org.elasticsearch.index.query.support.InnerHitsBuilder; import org.elasticsearch.index.query.support.NestedScope; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.indices.query.IndicesQueriesRegistry; @@ -69,7 +69,7 @@ import static java.util.Collections.unmodifiableMap; /** * Context object used to create lucene queries on the shard level. */ -public class QueryShardContext extends QueryRewriteContext { +public class QueryShardContext extends QueryRewriteContext implements ParseFieldMatcherSupplier { private final MapperService mapperService; private final SimilarityService similarityService; @@ -118,6 +118,7 @@ public class QueryShardContext extends QueryRewriteContext { this.parseContext.parseFieldMatcher(parseFieldMatcher); } + @Override public ParseFieldMatcher parseFieldMatcher() { return parseContext.parseFieldMatcher(); } diff --git a/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java index c3d8dc976ef..a4b5fdd806c 100644 --- a/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java @@ -476,7 +476,8 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder scoreFunction = scoreFunctionsRegistry.lookup(currentFieldName, parseContext.parser()) + ScoreFunctionBuilder scoreFunction = scoreFunctionsRegistry + .lookup(currentFieldName, parseContext.parser(), parseContext.parseFieldMatcher()) .fromXContent(parseContext); filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(scoreFunction)); } @@ -581,7 +582,8 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder, Void> INGEST_METADATA_PARSER = new ObjectParser<>("ingest_metadata", ArrayList::new); + private static final ObjectParser, ParseFieldMatcherSupplier> INGEST_METADATA_PARSER = new ObjectParser<>( + "ingest_metadata", ArrayList::new); static { INGEST_METADATA_PARSER.declareObjectArray(List::addAll , PipelineConfiguration.getParser(), PIPELINES_FIELD); @@ -94,7 +97,7 @@ public final class IngestMetadata implements MetaData.Custom { @Override public IngestMetadata fromXContent(XContentParser parser) throws IOException { Map pipelines = new HashMap<>(); - List configs = INGEST_METADATA_PARSER.parse(parser); + List configs = INGEST_METADATA_PARSER.parse(parser, () -> ParseFieldMatcher.STRICT); for (PipelineConfiguration pipeline : configs) { pipelines.put(pipeline.getId(), pipeline); } diff --git a/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java b/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java index d99d0e18c5c..6272eee1cbf 100644 --- a/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java +++ b/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java @@ -21,6 +21,7 @@ package org.elasticsearch.ingest; import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -46,7 +47,7 @@ public final class PipelineConfiguration extends AbstractDiffable PARSER = new ObjectParser<>("pipeline_config", Builder::new); + private final static ObjectParser PARSER = new ObjectParser<>("pipeline_config", Builder::new); static { PARSER.declareString(Builder::setId, new ParseField("id")); PARSER.declareField((parser, builder, aVoid) -> { @@ -56,7 +57,7 @@ public final class PipelineConfiguration extends AbstractDiffable getParser() { + public static BiFunction getParser() { return (p, c) -> PARSER.apply(p ,c).build(); } private static class Builder { @@ -110,6 +111,7 @@ public final class PipelineConfiguration extends AbstractDiffable TLP_PARSER = + private static ObjectParser TLP_PARSER = new ObjectParser<>(SUGGESTION_NAME, null); static { TLP_PARSER.declareStringArray(CompletionSuggestionBuilder.InnerBuilder::payload, PAYLOAD_FIELD); @@ -80,12 +82,12 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder - completionSuggestionContext.regexOptions = RegexOptions.parse(parser), + completionSuggestionContext.regexOptions = RegexOptions.parse(parser, context), RegexOptions.REGEX_OPTIONS, ObjectParser.ValueType.OBJECT); TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::field, SuggestUtils.Fields.FIELD); TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::analyzer, SuggestUtils.Fields.ANALYZER); @@ -263,7 +265,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder ParseFieldMatcher.STRICT); String field = builder.field; // now we should have field name, check and copy fields over to the suggestion builder we return if (field == null) { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java index ed2efdf4562..2977e8ad9a2 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.suggest.document.FuzzyCompletionQuery; import org.apache.lucene.util.automaton.Operations; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -56,7 +57,8 @@ public class FuzzyOptions implements ToXContent, Writeable { * "max_determinized_states" : INT * } */ - private static ObjectParser PARSER = new ObjectParser<>(FUZZY_OPTIONS.getPreferredName(), Builder::new); + private static ObjectParser PARSER = new ObjectParser<>(FUZZY_OPTIONS.getPreferredName(), + Builder::new); static { PARSER.declareInt(Builder::setFuzzyMinLength, MIN_LENGTH_FIELD); PARSER.declareInt(Builder::setMaxDeterminizedStates, MAX_DETERMINIZED_STATES_FIELD); @@ -111,8 +113,8 @@ public class FuzzyOptions implements ToXContent, Writeable { out.writeVInt(maxDeterminizedStates); } - static FuzzyOptions parse(XContentParser parser) throws IOException { - return PARSER.parse(parser).build(); + static FuzzyOptions parse(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException { + return PARSER.parse(parser, context).build(); } public static Builder builder() { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java index 58464cddee2..59ca2a6da14 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java @@ -23,6 +23,7 @@ import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.RegExp; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -48,7 +49,8 @@ public class RegexOptions implements ToXContent, Writeable { * "max_determinized_states" : INT * } */ - private static ObjectParser PARSER = new ObjectParser<>(REGEX_OPTIONS.getPreferredName(), Builder::new); + private static ObjectParser PARSER = new ObjectParser<>(REGEX_OPTIONS.getPreferredName(), + Builder::new); static { PARSER.declareInt(Builder::setMaxDeterminizedStates, MAX_DETERMINIZED_STATES); PARSER.declareField((parser, builder, aVoid) -> { @@ -105,8 +107,8 @@ public class RegexOptions implements ToXContent, Writeable { return new Builder(); } - static RegexOptions parse(XContentParser parser) throws IOException { - return PARSER.parse(parser).build(); + static RegexOptions parse(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException { + return PARSER.parse(parser, context).build(); } @Override diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java index 62892216c68..1384868f0dc 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java @@ -21,6 +21,8 @@ package org.elasticsearch.search.suggest.completion.context; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -95,7 +97,7 @@ public final class CategoryQueryContext implements ToXContent { return result; } - private static ObjectParser CATEGORY_PARSER = new ObjectParser<>(NAME, null); + private static ObjectParser CATEGORY_PARSER = new ObjectParser<>(NAME, null); static { CATEGORY_PARSER.declareString(Builder::setCategory, new ParseField(CONTEXT_VALUE)); CATEGORY_PARSER.declareInt(Builder::setBoost, new ParseField(CONTEXT_BOOST)); @@ -106,7 +108,7 @@ public final class CategoryQueryContext implements ToXContent { XContentParser.Token token = parser.currentToken(); Builder builder = builder(); if (token == XContentParser.Token.START_OBJECT) { - CATEGORY_PARSER.parse(parser, builder); + CATEGORY_PARSER.parse(parser, builder, () -> ParseFieldMatcher.STRICT); } else if (token == XContentParser.Token.VALUE_STRING) { builder.setCategory(parser.text()); } else { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java index 1d27f171594..dd625f252de 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java @@ -21,6 +21,8 @@ package org.elasticsearch.search.suggest.completion.context; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.common.xcontent.ObjectParser; @@ -111,7 +113,7 @@ public final class GeoQueryContext implements ToXContent { return new Builder(); } - private static ObjectParser GEO_CONTEXT_PARSER = new ObjectParser<>(NAME, null); + private static ObjectParser GEO_CONTEXT_PARSER = new ObjectParser<>(NAME, null); static { GEO_CONTEXT_PARSER.declareField((parser, geoQueryContext, geoContextMapping) -> geoQueryContext.setGeoPoint(GeoUtils.parseGeoPoint(parser)), new ParseField(CONTEXT_VALUE), ObjectParser.ValueType.OBJECT); GEO_CONTEXT_PARSER.declareInt(GeoQueryContext.Builder::setBoost, new ParseField(CONTEXT_BOOST)); @@ -127,7 +129,7 @@ public final class GeoQueryContext implements ToXContent { XContentParser.Token token = parser.currentToken(); GeoQueryContext.Builder builder = new Builder(); if (token == XContentParser.Token.START_OBJECT) { - GEO_CONTEXT_PARSER.parse(parser, builder); + GEO_CONTEXT_PARSER.parse(parser, builder, () -> ParseFieldMatcher.STRICT); } else if (token == XContentParser.Token.VALUE_STRING) { builder.setGeoPoint(GeoPoint.fromGeohash(parser.text())); } else { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java index d2fee7ccb30..0d4e269a5c4 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java @@ -375,13 +375,15 @@ public final class DirectCandidateGeneratorBuilder DirectCandidateGeneratorBuilder tempGenerator = new DirectCandidateGeneratorBuilder("_na_"); // bucket for the field name, needed as constructor arg later Set tmpFieldName = new HashSet<>(1); - PARSER.parse(parseContext.parser(), new Tuple, DirectCandidateGeneratorBuilder>(tmpFieldName, tempGenerator)); + PARSER.parse(parseContext.parser(), new Tuple, DirectCandidateGeneratorBuilder>(tmpFieldName, tempGenerator), + parseContext); if (tmpFieldName.size() != 1) { throw new IllegalArgumentException("[" + TYPE + "] expects exactly one field parameter, but found " + tmpFieldName); } return replaceField(tmpFieldName.iterator().next(), tempGenerator); } + @Override public PhraseSuggestionContext.DirectCandidateGenerator build(MapperService mapperService) throws IOException { PhraseSuggestionContext.DirectCandidateGenerator generator = new PhraseSuggestionContext.DirectCandidateGenerator(); generator.setField(this.field); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java index e1b55b735c0..2cd688a661c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands; import org.elasticsearch.cluster.routing.allocation.command.CancelAllocationCommand; import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -452,7 +453,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase { parser.nextToken(); AllocationCommandRegistry registry = new NetworkModule(null, Settings.EMPTY, true, new NamedWriteableRegistry()) .getAllocationCommandRegistry(); - AllocationCommands sCommands = AllocationCommands.fromXContent(parser, registry); + AllocationCommands sCommands = AllocationCommands.fromXContent(parser, ParseFieldMatcher.STRICT, registry); assertThat(sCommands.commands().size(), equalTo(5)); assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).shardId(), equalTo(1)); diff --git a/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java b/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java index ec4da62c2dd..abafd7e4cf3 100644 --- a/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java +++ b/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java @@ -18,22 +18,25 @@ */ package org.elasticsearch.common.xcontent; -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParsingException; -import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser; -import org.elasticsearch.common.xcontent.ObjectParser.ValueType; -import org.elasticsearch.test.ESTestCase; +import static org.hamcrest.Matchers.hasSize; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.hamcrest.Matchers.hasSize; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; +import org.elasticsearch.common.ParsingException; +import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser; +import org.elasticsearch.common.xcontent.ObjectParser.ValueType; +import org.elasticsearch.test.ESTestCase; public class ObjectParserTests extends ESTestCase { + private final static ParseFieldMatcherSupplier STRICT_PARSING = () -> ParseFieldMatcher.STRICT; + public void testBasics() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser( "{\n" @@ -53,14 +56,13 @@ public class ObjectParserTests extends ESTestCase { this.ints = ints; } } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING); objectParser.declareInt(TestStruct::setTestNumber, new ParseField("test_number")); objectParser.declareIntArray(TestStruct::setInts, new ParseField("test_array")); - parser.setParseFieldMatcher(ParseFieldMatcher.STRICT); - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); assertEquals(s.test, "foo"); assertEquals(s.testNumber, 2); assertEquals(s.ints, Arrays.asList(1, 2, 3, 4)); @@ -74,17 +76,17 @@ public class ObjectParserTests extends ESTestCase { public void testObjectOrDefault() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser("{\"object\" : { \"test\": 2}}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test")); objectParser.declareObjectOrDefault(StaticTestStruct::setObject, objectParser, StaticTestStruct::new, new ParseField("object")); - StaticTestStruct s = objectParser.parse(parser); + StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); assertEquals(s.object.test, 2); parser = XContentType.JSON.xContent().createParser("{\"object\" : false }"); - s = objectParser.parse(parser); + s = objectParser.parse(parser, STRICT_PARSING); assertNull(s.object); parser = XContentType.JSON.xContent().createParser("{\"object\" : true }"); - s = objectParser.parse(parser); + s = objectParser.parse(parser, STRICT_PARSING); assertNotNull(s.object); assertEquals(s.object.test, 0); @@ -96,12 +98,12 @@ public class ObjectParserTests extends ESTestCase { public void setTest(int test) { } } - ObjectParser objectParser = new ObjectParser<>("the_parser"); + ObjectParser objectParser = new ObjectParser<>("the_parser"); TestStruct s = new TestStruct(); objectParser.declareInt(TestStruct::setTest, new ParseField("test")); try { - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); fail("numeric value expected"); } catch (ParsingException ex) { assertEquals(ex.getMessage(), "[the_parser] failed to parse field [test]"); @@ -110,7 +112,7 @@ public class ObjectParserTests extends ESTestCase { parser = XContentType.JSON.xContent().createParser("{\"not_supported_field\" : \"foo\"}"); try { - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); fail("field not supported"); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "[the_parser] unknown field [not_supported_field], parser not found"); @@ -122,14 +124,13 @@ public class ObjectParserTests extends ESTestCase { class TestStruct { public String test; } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); objectParser.declareField((i, v, c) -> v.test = i.text(), new ParseField("test", "old_test"), ObjectParser.ValueType.STRING); - parser.setParseFieldMatcher(ParseFieldMatcher.STRICT); try { - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); fail("deprecated value"); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "Deprecated field [old_test] used, expected [test] instead"); @@ -137,8 +138,7 @@ public class ObjectParserTests extends ESTestCase { } assertNull(s.test); parser = XContentType.JSON.xContent().createParser("{\"old_test\" : \"foo\"}"); - parser.setParseFieldMatcher(ParseFieldMatcher.EMPTY); - objectParser.parse(parser, s); + objectParser.parse(parser, s, () -> ParseFieldMatcher.EMPTY); assertEquals("foo", s.test); } @@ -147,13 +147,12 @@ public class ObjectParserTests extends ESTestCase { class TestStruct { public String test; } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("numeric_value"), ObjectParser.ValueType.FLOAT); - parser.setParseFieldMatcher(ParseFieldMatcher.STRICT); try { - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); fail("wrong type - must be number"); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "[foo] numeric_value doesn't support values of type: VALUE_BOOLEAN"); @@ -166,39 +165,40 @@ public class ObjectParserTests extends ESTestCase { public int test; TestStruct object; } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); s.object = new TestStruct(); objectParser.declareField((i, c, x) -> c.test = i.intValue(), new ParseField("test"), ValueType.INT); - objectParser.declareField((i, c, x) -> objectParser.parse(parser, c.object), new ParseField("object"), ValueType.OBJECT); - objectParser.parse(parser, s); + objectParser.declareField((i, c, x) -> objectParser.parse(parser, c.object, STRICT_PARSING), new ParseField("object"), + ValueType.OBJECT); + objectParser.parse(parser, s, STRICT_PARSING); assertEquals(s.test, 1); assertEquals(s.object.test, 2); } public void testParseNestedShortcut() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser("{ \"test\" : 1, \"object\" : { \"test\": 2}}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test")); objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object")); - StaticTestStruct s = objectParser.parse(parser); + StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); assertEquals(s.test, 1); assertEquals(s.object.test, 2); } public void testEmptyObject() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser("{\"object\" : {}}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object")); - StaticTestStruct s = objectParser.parse(parser); + StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); assertNotNull(s.object); } public void testEmptyObjectInArray() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser("{\"object_array\" : [{}]}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareObjectArray(StaticTestStruct::setObjectArray, objectParser, new ParseField("object_array")); - StaticTestStruct s = objectParser.parse(parser); + StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); assertNotNull(s.objectArray); } @@ -233,9 +233,9 @@ public class ObjectParserTests extends ESTestCase { } } XContentParser parser = XContentType.JSON.xContent().createParser("{ \"test\" : \"FOO\" }"); - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); objectParser.declareString((struct, value) -> struct.set(TestEnum.valueOf(value)), new ParseField("test")); - TestStruct s = objectParser.parse(parser, new TestStruct()); + TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING); assertEquals(s.test, TestEnum.FOO); } @@ -329,7 +329,7 @@ public class ObjectParserTests extends ESTestCase { this.string_or_null = string_or_null; } } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); objectParser.declareInt(TestStruct::setInt_field, new ParseField("int_field")); objectParser.declareIntArray(TestStruct::setInt_array_field, new ParseField("int_array_field")); objectParser.declareLong(TestStruct::setLong_field, new ParseField("long_field")); @@ -343,7 +343,7 @@ public class ObjectParserTests extends ESTestCase { objectParser.declareStringOrNull(TestStruct::setString_or_null, new ParseField("string_or_null")); objectParser.declareBoolean(TestStruct::setNull_value, new ParseField("boolean_field")); - TestStruct parse = objectParser.parse(parser, new TestStruct()); + TestStruct parse = objectParser.parse(parser, new TestStruct(), STRICT_PARSING); assertArrayEquals(parse.double_array_field.toArray(), Arrays.asList(2.1d).toArray()); assertEquals(parse.double_field, 2.1d, 0.0d); @@ -372,7 +372,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": {\n" + " \"a\": {}" + "}}"); - NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, null); + NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING); assertThat(h.named, hasSize(1)); assertEquals("a", h.named.get(0).name); assertFalse(h.namedSuppliedInOrder); @@ -383,7 +383,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " {\"a\": {}}" + "]}"); - NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, null); + NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING); assertThat(h.named, hasSize(1)); assertEquals("a", h.named.get(0).name); assertTrue(h.namedSuppliedInOrder); @@ -394,7 +394,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " {\"a\": {}, \"b\": {}}" + "]}"); - ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null)); + ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals( "[named] can be a single object with any number of fields or an array where each entry is an object with a single field", @@ -406,7 +406,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " {}" + "]}"); - ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null)); + ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals( "[named] can be a single object with any number of fields or an array where each entry is an object with a single field", @@ -418,7 +418,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " \"junk\"" + "]}"); - ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null)); + ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals( "[named] can be a single object with any number of fields or an array where each entry is an object with a single field", @@ -432,17 +432,18 @@ public class ObjectParserTests extends ESTestCase { + "]}"); // Create our own parser for this test so we can disable support for the "ordered" mode specified by the array above - ObjectParser objectParser = new ObjectParser<>("named_object_holder", NamedObjectHolder::new); + ObjectParser objectParser = new ObjectParser<>("named_object_holder", + NamedObjectHolder::new); objectParser.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, new ParseField("named")); // Now firing the xml through it fails - ParsingException e = expectThrows(ParsingException.class, () -> objectParser.apply(parser, null)); + ParsingException e = expectThrows(ParsingException.class, () -> objectParser.apply(parser, STRICT_PARSING)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals("[named] doesn't support arrays. Use a single object with multiple fields.", e.getCause().getMessage()); } static class NamedObjectHolder { - public static final ObjectParser PARSER = new ObjectParser<>("named_object_holder", + public static final ObjectParser PARSER = new ObjectParser<>("named_object_holder", NamedObjectHolder::new); static { PARSER.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, NamedObjectHolder::keepNamedInOrder, @@ -462,11 +463,11 @@ public class ObjectParserTests extends ESTestCase { } public static class NamedObject { - public static final NamedObjectParser PARSER; + public static final NamedObjectParser PARSER; static { - ObjectParser parser = new ObjectParser<>("named"); + ObjectParser parser = new ObjectParser<>("named"); parser.declareInt(NamedObject::setFoo, new ParseField("foo")); - PARSER = (XContentParser p, Void v, String name) -> parser.parse(p, new NamedObject(name)); + PARSER = (XContentParser p, ParseFieldMatcherSupplier v, String name) -> parser.parse(p, new NamedObject(name), STRICT_PARSING); } final String name; diff --git a/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java b/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java index 31d9722eced..393321e8e06 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java +++ b/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java @@ -98,19 +98,17 @@ public class SearchModuleTests extends ModuleTestCase { IndicesQueriesRegistry indicesQueriesRegistry = module.getQueryParserRegistry(); XContentParser dummyParser = XContentHelper.createParser(new BytesArray("{}")); - dummyParser.setParseFieldMatcher(ParseFieldMatcher.EMPTY); for (String queryName : supportedQueries) { - indicesQueriesRegistry.lookup(queryName, dummyParser); + indicesQueriesRegistry.lookup(queryName, dummyParser, ParseFieldMatcher.EMPTY); } - dummyParser.setParseFieldMatcher(ParseFieldMatcher.STRICT); for (String queryName : NON_DEPRECATED_QUERIES) { - QueryParser queryParser = indicesQueriesRegistry.lookup(queryName, dummyParser); + QueryParser queryParser = indicesQueriesRegistry.lookup(queryName, dummyParser, ParseFieldMatcher.STRICT); assertThat(queryParser, notNullValue()); } for (String queryName : DEPRECATED_QUERIES) { try { - indicesQueriesRegistry.lookup(queryName, dummyParser); + indicesQueriesRegistry.lookup(queryName, dummyParser, ParseFieldMatcher.STRICT); fail("query is deprecated, getQueryParser should have failed in strict mode"); } catch(IllegalArgumentException e) { assertThat(e.getMessage(), containsString("Deprecated field [" + queryName + "] used")); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index 4603326e3a8..3833d59ef34 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -235,7 +235,7 @@ public abstract class BaseAggregationTestCase> assertSame(XContentParser.Token.FIELD_NAME, parser.nextToken()); assertEquals(testAgg.type.name(), parser.currentName()); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); - AggregatorBuilder newAgg = aggParsers.parser(testAgg.getType(), parser).parse(testAgg.name, parseContext); + AggregatorBuilder newAgg = aggParsers.parser(testAgg.getType(), ParseFieldMatcher.STRICT).parse(testAgg.name, parseContext); assertSame(XContentParser.Token.END_OBJECT, parser.currentToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java index a3d4ff46e42..4c9311bb110 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java @@ -237,7 +237,7 @@ public abstract class BasePipelineAggregationTestCase newAgg = aggParsers.pipelineParser(testAgg.getWriteableName(), parser) + PipelineAggregatorBuilder newAgg = aggParsers.pipelineParser(testAgg.getWriteableName(), ParseFieldMatcher.STRICT) .parse(testAgg.name(), parseContext); assertSame(XContentParser.Token.END_OBJECT, parser.currentToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java index 04499e2fcde..e4d134b8e38 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.aggregations.pipeline.moving.avg; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; @@ -116,8 +117,8 @@ public class MovAvgTests extends BasePipelineAggregationTestCase newAgg = aggParsers.pipelineParser(expected.getWriteableName(), parser).parse(expected.name(), - parseContext); + PipelineAggregatorBuilder newAgg = aggParsers.pipelineParser(expected.getWriteableName(), ParseFieldMatcher.STRICT) + .parse(expected.name(), parseContext); assertSame(XContentParser.Token.END_OBJECT, parser.currentToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); diff --git a/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java b/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java index c3dc8eab745..a5ef892bf17 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java @@ -47,7 +47,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -58,7 +58,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -69,7 +69,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -80,7 +80,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -91,7 +91,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -100,7 +100,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.field("location", new GeoPoint(1, 2)); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -109,7 +109,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.field("location", "1,2"); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -118,7 +118,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.field("location", "s3y0zh7w1z0g"); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -129,16 +129,36 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); } + public void testGeoDistanceSortDeprecatedSortModeException() throws Exception { + XContentBuilder mapping = jsonBuilder(); + mapping.startObject().startObject("type").startObject("properties").startObject("location").field("type", "geo_point").endObject().endObject().endObject().endObject(); + IndexService indexService = createIndex("testidx", Settings.builder().build(), "type", mapping); + TestSearchContext context = (TestSearchContext) createSearchContext(indexService); + context.getQueryShardContext().setTypes("type"); + + XContentBuilder sortBuilder = jsonBuilder(); + sortBuilder.startObject(); + sortBuilder.startArray("location"); + sortBuilder.startArray().value(1.2).value(3).endArray().startArray().value(5).value(6).endArray(); + sortBuilder.endArray(); + sortBuilder.field("order", "desc"); + sortBuilder.field("unit", "km"); + sortBuilder.field("sort_mode", "max"); + sortBuilder.endObject(); + IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> parse(context, sortBuilder)); + assertEquals("Deprecated field [sort_mode] used, expected [mode] instead", ex.getMessage()); + } + protected void parse(TestSearchContext context, XContentBuilder sortBuilder) throws Exception { QueryParseContext parseContext = context.getQueryShardContext().parseContext(); XContentParser parser = XContentHelper.createParser(sortBuilder.bytes()); - parser.setParseFieldMatcher(ParseFieldMatcher.STRICT); parseContext.reset(parser); + parseContext.parseFieldMatcher(ParseFieldMatcher.STRICT); parser.nextToken(); GeoDistanceSortBuilder.fromXContent(parseContext, null); } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java index 8f6fe71d46e..fc5f1c69ecd 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java @@ -33,6 +33,8 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -80,7 +82,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler destParser = new ObjectParser<>("dest"); + ObjectParser destParser = new ObjectParser<>("dest"); destParser.declareString(IndexRequest::index, new ParseField("index")); destParser.declareString(IndexRequest::type, new ParseField("type")); destParser.declareString(IndexRequest::routing, new ParseField("routing")); @@ -94,7 +96,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler sourceParser.parse(p, v.getSearchRequest(), c), new ParseField("source"), ValueType.OBJECT); - PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), null), new ParseField("dest"), 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.queryParseContext.parseFieldMatcher())), new ParseField("script"), ValueType.OBJECT); @@ -169,7 +171,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler Date: Fri, 15 Apr 2016 12:05:45 +0200 Subject: [PATCH 2/2] Rename context.parseFieldMatcher() to context.getParseFieldMatcher --- .../common/ParseFieldMatcherSupplier.java | 2 +- .../common/xcontent/ObjectParser.java | 2 +- .../index/query/BoolQueryBuilder.java | 12 ++-- .../index/query/BoostingQueryBuilder.java | 10 +-- .../index/query/CommonTermsQueryBuilder.java | 24 +++---- .../query/ConstantScoreQueryBuilder.java | 6 +- .../index/query/DisMaxQueryBuilder.java | 10 +-- .../index/query/ExistsQueryBuilder.java | 6 +- .../query/FieldMaskingSpanQueryBuilder.java | 8 +-- .../index/query/FuzzyQueryBuilder.java | 20 +++--- .../query/GeoBoundingBoxQueryBuilder.java | 32 ++++----- .../index/query/GeoDistanceQueryBuilder.java | 20 +++--- .../query/GeoDistanceRangeQueryBuilder.java | 34 ++++----- .../index/query/GeoPolygonQueryBuilder.java | 10 +-- .../index/query/GeoShapeQueryBuilder.java | 22 +++--- .../index/query/GeohashCellQuery.java | 10 +-- .../index/query/HasChildQueryBuilder.java | 18 ++--- .../index/query/HasParentQueryBuilder.java | 16 ++--- .../index/query/IdsQueryBuilder.java | 10 +-- .../index/query/IndicesQueryBuilder.java | 14 ++-- .../index/query/MatchAllQueryBuilder.java | 4 +- .../index/query/MatchNoneQueryBuilder.java | 4 +- .../query/MatchPhrasePrefixQueryBuilder.java | 12 ++-- .../index/query/MatchPhraseQueryBuilder.java | 10 +-- .../index/query/MatchQueryBuilder.java | 34 ++++----- .../index/query/MoreLikeThisQueryBuilder.java | 48 ++++++------- .../index/query/MultiMatchQueryBuilder.java | 40 +++++------ .../index/query/NestedQueryBuilder.java | 14 ++-- .../index/query/ParentIdQueryBuilder.java | 10 +-- .../index/query/PercolatorQueryBuilder.java | 20 +++--- .../index/query/PrefixQueryBuilder.java | 10 +-- .../index/query/QueryParseContext.java | 2 +- .../index/query/QueryRewriteContext.java | 15 +++- .../index/query/QueryShardContext.java | 28 +++----- .../index/query/QueryStringQueryBuilder.java | 60 ++++++++-------- .../index/query/RangeQueryBuilder.java | 28 ++++---- .../index/query/RegexpQueryBuilder.java | 18 ++--- .../index/query/ScriptQueryBuilder.java | 12 ++-- .../index/query/SimpleQueryStringBuilder.java | 24 +++---- .../query/SpanContainingQueryBuilder.java | 8 +-- .../index/query/SpanFirstQueryBuilder.java | 8 +-- .../query/SpanMultiTermQueryBuilder.java | 6 +- .../index/query/SpanNearQueryBuilder.java | 12 ++-- .../index/query/SpanNotQueryBuilder.java | 14 ++-- .../index/query/SpanOrQueryBuilder.java | 6 +- .../index/query/SpanTermQueryBuilder.java | 8 +-- .../index/query/SpanWithinQueryBuilder.java | 8 +-- .../index/query/TemplateQueryBuilder.java | 2 +- .../index/query/TermQueryBuilder.java | 8 +-- .../index/query/TermsQueryBuilder.java | 4 +- .../index/query/TypeQueryBuilder.java | 6 +- .../index/query/WildcardQueryBuilder.java | 12 ++-- .../index/query/WrapperQueryBuilder.java | 2 +- .../functionscore/DecayFunctionParser.java | 2 +- .../FunctionScoreQueryBuilder.java | 26 +++---- .../ScriptScoreFunctionBuilder.java | 6 +- .../action/search/RestMultiSearchAction.java | 2 +- .../rest/action/search/RestSearchAction.java | 2 +- .../aggregations/AggregatorParsers.java | 4 +- .../filters/FiltersAggregatorBuilder.java | 30 ++++---- .../bucket/nested/NestedParser.java | 2 +- .../bucket/sampler/SamplerParser.java | 2 +- .../ScriptedMetricAggregatorBuilder.java | 22 +++--- .../metrics/tophits/TopHitsParser.java | 42 +++++------ .../aggregations/pipeline/BucketHelpers.java | 2 +- .../bucketmetrics/BucketMetricsParser.java | 8 +-- .../bucketscript/BucketScriptParser.java | 18 ++--- .../bucketselector/BucketSelectorParser.java | 16 ++--- .../cumulativesum/CumulativeSumParser.java | 6 +- .../DerivativePipelineAggregatorBuilder.java | 26 +++---- .../pipeline/movavg/MovAvgParser.java | 20 +++--- .../pipeline/serialdiff/SerialDiffParser.java | 10 +-- .../support/AbstractValuesSourceParser.java | 14 ++-- .../search/builder/SearchSourceBuilder.java | 72 +++++++++---------- .../fetch/source/FetchSourceContext.java | 8 +-- .../search/rescore/RescoreBuilder.java | 2 +- .../search/sort/FieldSortBuilder.java | 12 ++-- .../search/sort/GeoDistanceSortBuilder.java | 2 +- .../search/sort/ScoreSortBuilder.java | 2 +- .../search/sort/ScriptSortBuilder.java | 2 +- .../search/suggest/SuggestBuilder.java | 2 +- .../search/suggest/SuggestionBuilder.java | 2 +- .../search/suggest/phrase/Laplace.java | 2 +- .../suggest/phrase/LinearInterpolation.java | 2 +- .../phrase/PhraseSuggestionBuilder.java | 2 +- .../search/suggest/phrase/SmoothingModel.java | 2 +- .../search/suggest/phrase/StupidBackoff.java | 2 +- .../suggest/term/TermSuggestionBuilder.java | 2 +- .../suggest/CustomSuggesterSearchIT.java | 2 +- .../index/reindex/RestReindexAction.java | 4 +- 90 files changed, 583 insertions(+), 582 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java b/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java index b2b7b51ffcb..672890c2b97 100644 --- a/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java +++ b/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java @@ -32,5 +32,5 @@ public interface ParseFieldMatcherSupplier { /** * @return the parseFieldMatcher */ - ParseFieldMatcher parseFieldMatcher(); + ParseFieldMatcher getParseFieldMatcher(); } diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java index a9f6518211c..0f3d899152b 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java @@ -129,7 +129,7 @@ public final class ObjectParser { } } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, DISABLE_COORD_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, DISABLE_COORD_FIELD)) { disableCoord = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH)) { minimumShouldMatch = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_NUMBER_SHOULD_MATCH)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MINIMUM_NUMBER_SHOULD_MATCH)) { minimumShouldMatch = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, ADJUST_PURE_NEGATIVE)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, ADJUST_PURE_NEGATIVE)) { adjustPureNegative = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[bool] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java index abfa400da69..2d263fa08ee 100644 --- a/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java @@ -154,21 +154,21 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT) { - if (parseContext.parseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) { queriesFound = true; QueryBuilder query = parseContext.parseInnerQueryBuilder(); queries.add(query); @@ -146,7 +146,7 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]"); } } else if (token == XContentParser.Token.START_ARRAY) { - if (parseContext.parseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) { queriesFound = true; while (token != XContentParser.Token.END_ARRAY) { QueryBuilder query = parseContext.parseInnerQueryBuilder(); @@ -157,11 +157,11 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]"); } } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TIE_BREAKER_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TIE_BREAKER_FIELD)) { tieBreaker = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java index cf7a72ebde5..dec6baf067c 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java @@ -98,11 +98,11 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, FIELD_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, FIELD_FIELD)) { fieldPattern = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); } else { throw new ParsingException(parser.getTokenLocation(), "[" + ExistsQueryBuilder.NAME + diff --git a/core/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java index 40f14574981..37a2be96280 100644 --- a/core/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java @@ -118,7 +118,7 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder i if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, TERM_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, TERM_FIELD)) { value = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { value = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) { fuzziness = Fuzziness.parse(parser); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) { prefixLength = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) { maxExpansions = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TRANSPOSITIONS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TRANSPOSITIONS_FIELD)) { transpositions = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { rewrite = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[fuzzy] query does not support [" + currentFieldName + "]"); @@ -348,7 +348,7 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder i query = new FuzzyQuery(new Term(fieldName, BytesRefs.toBytesRef(value)), maxEdits, prefixLength, maxExpansions, transpositions); } if (query instanceof MultiTermQuery) { - MultiTermQuery.RewriteMethod rewriteMethod = QueryParsers.parseRewriteMethod(context.parseFieldMatcher(), rewrite, null); + MultiTermQuery.RewriteMethod rewriteMethod = QueryParsers.parseRewriteMethod(context.getParseFieldMatcher(), rewrite, null); QueryParsers.setRewriteMethod((MultiTermQuery) query, rewriteMethod); } return query; diff --git a/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java index a685145e081..db743b971c7 100644 --- a/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java @@ -418,30 +418,30 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder(); while ((token = parser.nextToken()) != Token.END_ARRAY) { shell.add(GeoUtils.parseGeoPoint(parser)); @@ -288,16 +288,16 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_ARRAY) { - if (parseContext.parseFieldMatcher().match(currentFieldName, VALUES_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUES_FIELD)) { idsProvided = true; while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if ((token == XContentParser.Token.VALUE_STRING) || @@ -156,7 +156,7 @@ public class IdsQueryBuilder extends AbstractQueryBuilder { "Illegal value for id, expecting a string or number, got: " + token); } } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String value = parser.textOrNull(); if (value == null) { @@ -169,11 +169,11 @@ public class IdsQueryBuilder extends AbstractQueryBuilder { "] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { types = Collections.singletonList(parser.text()); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[" + IdsQueryBuilder.NAME + diff --git a/core/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java index d5caa16ea71..e3f6e32eb19 100644 --- a/core/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java @@ -157,15 +157,15 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder { matchQuery.setFuzzyPrefixLength(prefixLength); matchQuery.setMaxExpansions(maxExpansions); matchQuery.setTranspositions(fuzzyTranspositions); - matchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(context.parseFieldMatcher(), fuzzyRewrite, null)); + matchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(context.getParseFieldMatcher(), fuzzyRewrite, null)); matchQuery.setLenient(lenient); matchQuery.setCommonTermsCutoff(cutoffFrequency); matchQuery.setZeroTermsQuery(zeroTermsQuery); @@ -540,9 +540,9 @@ public class MatchQueryBuilder extends AbstractQueryBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { value = parser.objectText(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { String tStr = parser.text(); if ("boolean".equals(tStr)) { type = MatchQuery.Type.BOOLEAN; @@ -553,31 +553,31 @@ public class MatchQueryBuilder extends AbstractQueryBuilder { } else { throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query does not support type " + tStr); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, ANALYZER_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, ANALYZER_FIELD)) { analyzer = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, SLOP_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, SLOP_FIELD)) { slop = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) { fuzziness = Fuzziness.parse(parser); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) { prefixLength = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) { maxExpansion = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, OPERATOR_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, OPERATOR_FIELD)) { operator = Operator.fromString(parser.text()); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) { minimumShouldMatch = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_REWRITE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FUZZY_REWRITE_FIELD)) { fuzzyRewrite = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_TRANSPOSITIONS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FUZZY_TRANSPOSITIONS_FIELD)) { fuzzyTranspositions = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, LENIENT_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, LENIENT_FIELD)) { lenient = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, CUTOFF_FREQUENCY_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, CUTOFF_FREQUENCY_FIELD)) { cutOffFrequency = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, ZERO_TERMS_QUERY_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, ZERO_TERMS_QUERY_FIELD)) { String zeroTermsDocs = parser.text(); if ("none".equalsIgnoreCase(zeroTermsDocs)) { zeroTermsQuery = MatchQuery.ZeroTermsQuery.NONE; @@ -587,7 +587,7 @@ public class MatchQueryBuilder extends AbstractQueryBuilder { throw new ParsingException(parser.getTokenLocation(), "Unsupported zero_terms_docs value [" + zeroTermsDocs + "]"); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index 1973a6a4772..b72122439b7 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -841,33 +841,33 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { fields.add(parser.text()); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.LIKE)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.LIKE)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { parseLikeField(parseContext, likeTexts, likeItems); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.UNLIKE)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.UNLIKE)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { parseLikeField(parseContext, unlikeTexts, unlikeItems); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.IDS)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.IDS)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (!token.isValue()) { throw new IllegalArgumentException("ids array element should only contain ids"); } likeItems.add(new Item(null, null, parser.text())); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.DOCS)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.DOCS)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token != XContentParser.Token.START_OBJECT) { throw new IllegalArgumentException("docs array element should include an object"); } - likeItems.add(Item.parse(parser, parseContext.parseFieldMatcher(), new Item())); + likeItems.add(Item.parse(parser, parseContext.getParseFieldMatcher(), new Item())); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.STOP_WORDS)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.STOP_WORDS)) { stopWords = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { stopWords.add(parser.text()); @@ -913,9 +913,9 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT) { - if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { query = parseContext.parseInnerQueryBuilder(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) { innerHitBuilder = InnerHitBuilder.fromXContent(parseContext); } else { throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, PATH_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, PATH_FIELD)) { path = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, IGNORE_UNMAPPED_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, IGNORE_UNMAPPED_FIELD)) { ignoreUnmapped = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_MODE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, SCORE_MODE_FIELD)) { scoreMode = HasChildQueryBuilder.parseScoreMode(parser.text()); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/ParentIdQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ParentIdQueryBuilder.java index 5d664a132ad..419149ce992 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ParentIdQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ParentIdQueryBuilder.java @@ -130,15 +130,15 @@ public final class ParentIdQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, PREFIX_FIELD)) { value = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { rewrite = parser.textOrNull(); } else { throw new ParsingException(parser.getTokenLocation(), @@ -176,7 +176,7 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder @Override protected Query doToQuery(QueryShardContext context) throws IOException { - MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(context.parseFieldMatcher(), rewrite, null); + MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(context.getParseFieldMatcher(), rewrite, null); Query query = null; MappedFieldType fieldType = context.fieldMapper(fieldName); diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index ee6c49234fd..c98ca70fc23 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -124,7 +124,7 @@ public class QueryParseContext implements ParseFieldMatcherSupplier { } @Override - public ParseFieldMatcher parseFieldMatcher() { + public ParseFieldMatcher getParseFieldMatcher() { return parseFieldMatcher; } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java index 70de640539f..43535d689a9 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java @@ -20,6 +20,8 @@ package org.elasticsearch.index.query; import org.apache.lucene.index.IndexReader; import org.elasticsearch.client.Client; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.indices.query.IndicesQueriesRegistry; @@ -28,7 +30,7 @@ import org.elasticsearch.script.ScriptService; /** * Context object used to rewrite {@link QueryBuilder} instances into simplified version. */ -public class QueryRewriteContext { +public class QueryRewriteContext implements ParseFieldMatcherSupplier { protected final MapperService mapperService; protected final ScriptService scriptService; protected final IndexSettings indexSettings; @@ -80,12 +82,21 @@ public class QueryRewriteContext { return reader; } + public void parseFieldMatcher(ParseFieldMatcher parseFieldMatcher) { + this.parseContext.parseFieldMatcher(parseFieldMatcher); + } + + @Override + public ParseFieldMatcher getParseFieldMatcher() { + return parseContext.getParseFieldMatcher(); + } + /** * Returns a new {@link QueryParseContext} to parse template or wrapped queries. */ public QueryParseContext newParseContext() { QueryParseContext queryParseContext = new QueryParseContext(indicesQueriesRegistry); - queryParseContext.parseFieldMatcher(parseContext.parseFieldMatcher()); + queryParseContext.parseFieldMatcher(parseContext.getParseFieldMatcher()); return queryParseContext; } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java index 6420c235c2e..340bf0e9715 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -19,6 +19,14 @@ package org.elasticsearch.index.query; +import static java.util.Collections.unmodifiableMap; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.IndexReader; import org.apache.lucene.queryparser.classic.MapperQueryParser; @@ -29,7 +37,6 @@ import org.apache.lucene.search.similarities.Similarity; import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -58,18 +65,10 @@ import org.elasticsearch.search.fetch.innerhits.InnerHitsContext; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.lookup.SearchLookup; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import static java.util.Collections.unmodifiableMap; - /** * Context object used to create lucene queries on the shard level. */ -public class QueryShardContext extends QueryRewriteContext implements ParseFieldMatcherSupplier { +public class QueryShardContext extends QueryRewriteContext { private final MapperService mapperService; private final SimilarityService similarityService; @@ -114,15 +113,6 @@ public class QueryShardContext extends QueryRewriteContext implements ParseField this.types = source.getTypes(); } - public void parseFieldMatcher(ParseFieldMatcher parseFieldMatcher) { - this.parseContext.parseFieldMatcher(parseFieldMatcher); - } - - @Override - public ParseFieldMatcher parseFieldMatcher() { - return parseContext.parseFieldMatcher(); - } - public void reset() { allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields(); this.parseFieldMatcher(ParseFieldMatcher.EMPTY); diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java index e49b0cace4f..6806ae944c2 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java @@ -667,7 +667,7 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder i if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, FROM_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, FROM_FIELD)) { from = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TO_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TO_FIELD)) { to = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, INCLUDE_LOWER_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, INCLUDE_LOWER_FIELD)) { includeLower = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, INCLUDE_UPPER_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, INCLUDE_UPPER_FIELD)) { includeUpper = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, GT_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, GT_FIELD)) { from = parser.objectBytes(); includeLower = false; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, GTE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, GTE_FIELD)) { from = parser.objectBytes(); includeLower = true; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, LT_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, LT_FIELD)) { to = parser.objectBytes(); includeUpper = false; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, LTE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, LTE_FIELD)) { to = parser.objectBytes(); includeUpper = true; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TIME_ZONE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TIME_ZONE_FIELD)) { timeZone = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) { format = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), @@ -358,9 +358,9 @@ public class RangeQueryBuilder extends AbstractQueryBuilder i } } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FIELDDATA_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FIELDDATA_FIELD)) { // ignore } else { throw new ParsingException(parser.getTokenLocation(), "[range] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java index 7a19d1f719e..c895830d5a5 100644 --- a/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java @@ -203,20 +203,20 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { value = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { rewrite = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FLAGS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FLAGS_FIELD)) { String flags = parser.textOrNull(); flagsValue = RegexpFlag.resolveValue(flags); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_DETERMINIZED_STATES_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MAX_DETERMINIZED_STATES_FIELD)) { maxDeterminizedStates = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FLAGS_VALUE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FLAGS_VALUE_FIELD)) { flagsValue = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), @@ -225,7 +225,7 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder } } } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, NAME_FIELD)) { queryName = parser.text(); } else { fieldName = currentFieldName; @@ -252,7 +252,7 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder @Override protected Query doToQuery(QueryShardContext context) throws QueryShardException, IOException { - MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(context.parseFieldMatcher(), rewrite, null); + MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(context.getParseFieldMatcher(), rewrite, null); Query query = null; MappedFieldType fieldType = context.fieldMapper(fieldName); 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 794160881f5..65be61d672b 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java @@ -112,20 +112,20 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder } else if (parseContext.isDeprecatedSetting(currentFieldName)) { // skip } else if (token == XContentParser.Token.START_OBJECT) { - if (parseContext.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, parseContext.parseFieldMatcher()); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, PARAMS_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, parseContext.getParseFieldMatcher()); + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, PARAMS_FIELD)) { // TODO remove in 3.0 (here to support old script APIs) params = parser.map(); } else { throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (!scriptParameterParser.token(currentFieldName, token, parser, parseContext.parseFieldMatcher())) { + } else if (!scriptParameterParser.token(currentFieldName, token, parser, parseContext.getParseFieldMatcher())) { throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]"); } } diff --git a/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java b/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java index 86c32ea3670..5e2c88af923 100644 --- a/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java @@ -439,7 +439,7 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder)) { throw new ParsingException(parser.getTokenLocation(), "span_containing [big] must be of type span query"); } big = (SpanQueryBuilder) query; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, LITTLE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, LITTLE_FIELD)) { QueryBuilder query = parseContext.parseInnerQueryBuilder(); if (!(query instanceof SpanQueryBuilder)) { throw new ParsingException(parser.getTokenLocation(), "span_containing [little] must be of type span query"); @@ -131,9 +131,9 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_ARRAY) { - if (parseContext.parseFieldMatcher().match(currentFieldName, CLAUSES_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, CLAUSES_FIELD)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { QueryBuilder query = parseContext.parseInnerQueryBuilder(); if (!(query instanceof SpanQueryBuilder)) { @@ -121,9 +121,9 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]"); } } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java index ac90148ef53..a4bafc5001c 100644 --- a/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java @@ -115,13 +115,13 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, TERM_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, TERM_FIELD)) { value = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { value = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java index 2ffe90faf74..19fe8da3011 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java @@ -271,9 +271,9 @@ public class TermsQueryBuilder extends AbstractQueryBuilder { fieldName = currentFieldName; termsLookup = TermsLookup.parseTermsLookup(parser); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java index 1e4490cfabf..129b0275527 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java @@ -94,11 +94,11 @@ public class TypeQueryBuilder extends AbstractQueryBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { type = parser.utf8Bytes(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java index 13a28d93b89..bf6921e9452 100644 --- a/core/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java @@ -155,15 +155,15 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder> im XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); functionBytes = builder.bytes(); - } else if (context.parseFieldMatcher().match(currentFieldName, MULTI_VALUE_MODE)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, MULTI_VALUE_MODE)) { multiValueMode = MultiValueMode.fromString(parser.text()); } else { throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters."); diff --git a/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java index a4b5fdd806c..3fcfa257c86 100644 --- a/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java @@ -454,7 +454,7 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder scoreFunction = scoreFunctionsRegistry - .lookup(currentFieldName, parseContext.parser(), parseContext.parseFieldMatcher()) + .lookup(currentFieldName, parseContext.parser(), parseContext.getParseFieldMatcher()) .fromXContent(parseContext); filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(scoreFunction)); } } else if (token == XContentParser.Token.START_ARRAY) { - if (parseContext.parseFieldMatcher().match(currentFieldName, FUNCTIONS_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, FUNCTIONS_FIELD)) { if (singleFunctionFound) { String errorString = "already found [" + singleFunctionName + "], now encountering [functions]."; handleMisplacedFunctionsDeclaration(parser.getTokenLocation(), errorString); @@ -495,17 +495,17 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder { public static final String NAME = InternalFilters.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); @@ -220,21 +220,21 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder(); String key = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -243,7 +243,7 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder filter = queryParseContext.parseInnerQueryBuilder(); keyedFilters.add(new FiltersAggregator.KeyedFilter(key, filter == null ? matchAllQuery() : filter)); } @@ -253,12 +253,12 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry); queryParseContext.reset(parser); - queryParseContext.parseFieldMatcher(context.parseFieldMatcher()); + queryParseContext.parseFieldMatcher(context.getParseFieldMatcher()); QueryBuilder filter = queryParseContext.parseInnerQueryBuilder(); nonKeyedFilters.add(filter == null ? QueryBuilders.matchAllQuery() : filter); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java index fb2fe3b701c..7584eb9148f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java @@ -46,7 +46,7 @@ public class NestedParser implements Aggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, NestedAggregator.PATH_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, NestedAggregator.PATH_FIELD)) { path = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java index 4a366511ca1..22efaf4f28c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java @@ -48,7 +48,7 @@ public class SamplerParser implements Aggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_NUMBER) { - if (context.parseFieldMatcher().match(currentFieldName, SamplerAggregator.SHARD_SIZE_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, SamplerAggregator.SHARD_SIZE_FIELD)) { shardSize = parser.intValue(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java index 355fdd76b98..677fd7b1617 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java @@ -240,24 +240,24 @@ public class ScriptedMetricAggregatorBuilder extends AggregatorBuilder fieldNames = new ArrayList<>(); fieldNames.add(parser.text()); factory.fields(fieldNames); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { factory.sort(parser.text()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { factory.fetchSource(FetchSourceContext.parse(context)); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELDS_FIELD)) { List scriptFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { String scriptFieldName = parser.currentName(); @@ -90,9 +90,9 @@ public class TopHitsParser implements Aggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (context.parseFieldMatcher().match(currentFieldName, + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.IGNORE_FAILURE_FIELD)) { ignoreFailure = parser.booleanValue(); } else { @@ -101,8 +101,8 @@ public class TopHitsParser implements Aggregator.Parser { parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { - script = Script.parse(parser, context.parseFieldMatcher()); + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", @@ -120,9 +120,9 @@ public class TopHitsParser implements Aggregator.Parser { } } factory.scriptFields(scriptFields); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.HIGHLIGHT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.HIGHLIGHT_FIELD)) { factory.highlighter(HighlightBuilder.fromXContent(context)); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { List> sorts = SortBuilder.fromXContent(context); factory.sorts(sorts); } else { @@ -131,7 +131,7 @@ public class TopHitsParser implements Aggregator.Parser { } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDS_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDS_FIELD)) { List fieldNames = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -142,7 +142,7 @@ public class TopHitsParser implements Aggregator.Parser { } } factory.fields(fieldNames); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDDATA_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDDATA_FIELDS_FIELD)) { List fieldDataFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -153,10 +153,10 @@ public class TopHitsParser implements Aggregator.Parser { } } factory.fieldDataFields(fieldDataFields); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { List> sorts = SortBuilder.fromXContent(context); factory.sorts(sorts); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { factory.fetchSource(FetchSourceContext.parse(context)); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java index 98d364bcd07..21337b73043 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java @@ -64,7 +64,7 @@ public class BucketHelpers { public static GapPolicy parse(QueryParseContext context, String text, XContentLocation tokenLocation) { GapPolicy result = null; for (GapPolicy policy : values()) { - if (context.parseFieldMatcher().match(text, policy.parseField)) { + if (context.getParseFieldMatcher().match(text, policy.parseField)) { if (result == null) { result = policy; } else { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java index dd2c4b20630..dbd0a5d128c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java @@ -59,17 +59,17 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPaths = new String[] { parser.text() }; - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); } else { leftover.put(currentFieldName, parser.text()); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java index 91c9daecb84..9ec7cd40527 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java @@ -59,21 +59,21 @@ public class BucketScriptParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPathsMap = new HashMap<>(); bucketsPathsMap.put("_value", parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); - } else if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); @@ -88,9 +88,9 @@ public class BucketScriptParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { Map map = parser.map(); bucketsPathsMap = new HashMap<>(); for (Map.Entry entry : map.entrySet()) { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java index 8573cc737a8..320331afac4 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java @@ -58,19 +58,19 @@ public class BucketSelectorParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPathsMap = new HashMap<>(); bucketsPathsMap.put("_value", parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); - } else if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); @@ -85,9 +85,9 @@ public class BucketSelectorParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { Map map = parser.map(); bucketsPathsMap = new HashMap<>(); for (Map.Entry entry : map.entrySet()) { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java index de0c9531477..1ae71c0f017 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java @@ -52,16 +52,16 @@ public class CumulativeSumParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPaths = new String[] { parser.text() }; } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java index f897bc6eafd..01238b48d53 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java @@ -19,6 +19,12 @@ package org.elasticsearch.search.aggregations.pipeline.derivative; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; @@ -33,20 +39,14 @@ import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; +import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuilder { public static final String NAME = DerivativePipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); - + private static final ParseField FORMAT_FIELD = new ParseField("format"); private static final ParseField GAP_POLICY_FIELD = new ParseField("gap_policy"); private static final ParseField UNIT_FIELD = new ParseField("unit"); @@ -204,20 +204,20 @@ public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuild if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { bucketsPaths = new String[] { parser.text() }; - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY_FIELD)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); - } else if (context.parseFieldMatcher().match(currentFieldName, UNIT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, UNIT_FIELD)) { units = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java index d3af7cb95a0..1c63099c745 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java @@ -74,13 +74,13 @@ public class MovAvgParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_NUMBER) { - if (context.parseFieldMatcher().match(currentFieldName, WINDOW)) { + if (context.getParseFieldMatcher().match(currentFieldName, WINDOW)) { window = parser.intValue(); if (window <= 0) { throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive, " + "non-zero integer. Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "]."); } - } else if (context.parseFieldMatcher().match(currentFieldName, PREDICT)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, PREDICT)) { predict = parser.intValue(); if (predict <= 0) { throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive integer." @@ -91,20 +91,20 @@ public class MovAvgParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPaths = new String[] { parser.text() }; - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); - } else if (context.parseFieldMatcher().match(currentFieldName, MODEL)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, MODEL)) { model = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); @@ -116,14 +116,14 @@ public class MovAvgParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, SETTINGS)) { + if (context.getParseFieldMatcher().match(currentFieldName, SETTINGS)) { settings = parser.map(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.VALUE_BOOLEAN) { - if (context.parseFieldMatcher().match(currentFieldName, MINIMIZE)) { + if (context.getParseFieldMatcher().match(currentFieldName, MINIMIZE)) { minimize = parser.booleanValue(); } else { throw new ParsingException(parser.getTokenLocation(), @@ -163,7 +163,7 @@ public class MovAvgParser implements PipelineAggregator.Parser { MovAvgModel movAvgModel; try { - movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.parseFieldMatcher()); + movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.getParseFieldMatcher()); } catch (ParseException exception) { throw new ParsingException(parser.getTokenLocation(), "Could not parse settings for model [" + model + "].", exception); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java index 8a2a0df2edb..5eb9858a6dc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java @@ -55,18 +55,18 @@ public class SerialDiffParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPaths = new String[] { parser.text() }; - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.VALUE_NUMBER) { - if (context.parseFieldMatcher().match(currentFieldName, LAG)) { + if (context.getParseFieldMatcher().match(currentFieldName, LAG)) { lag = parser.intValue(true); if (lag <= 0) { throw new ParsingException(parser.getTokenLocation(), @@ -79,7 +79,7 @@ public class SerialDiffParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/AbstractValuesSourceParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/AbstractValuesSourceParser.java index d864fc97664..bf68f4d59f2 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/support/AbstractValuesSourceParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/AbstractValuesSourceParser.java @@ -103,7 +103,7 @@ public abstract class AbstractValuesSourceParser currentFieldName = parser.currentName(); } else if ("missing".equals(currentFieldName) && token.isValue()) { missing = parser.objectText(); - } else if (timezoneAware && context.parseFieldMatcher().match(currentFieldName, TIME_ZONE)) { + } else if (timezoneAware && context.getParseFieldMatcher().match(currentFieldName, TIME_ZONE)) { if (token == XContentParser.Token.VALUE_STRING) { timezone = DateTimeZone.forID(parser.text()); } else if (token == XContentParser.Token.VALUE_NUMBER) { @@ -126,22 +126,22 @@ public abstract class AbstractValuesSourceParser + valueType + "]. [" + type() + "] aggregation can only work on value of type [" + targetValueType + "]"); } - } else if (!token(aggregationName, currentFieldName, token, parser, context.parseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } - } else if (!token(aggregationName, currentFieldName, token, parser, context.parseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } } else if (scriptable && token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (!token(aggregationName, currentFieldName, token, parser, context.parseFieldMatcher(), otherOptions)) { + if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } - } else if (!token(aggregationName, currentFieldName, token, parser, context.parseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } 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 a0cd54d4d87..a39d0273c2f 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -995,47 +995,47 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (context.parseFieldMatcher().match(currentFieldName, FROM_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, FROM_FIELD)) { from = parser.intValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, SIZE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SIZE_FIELD)) { size = parser.intValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, TIMEOUT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, TIMEOUT_FIELD)) { timeoutInMillis = parser.longValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, TERMINATE_AFTER_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, TERMINATE_AFTER_FIELD)) { terminateAfter = parser.intValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, MIN_SCORE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, MIN_SCORE_FIELD)) { minScore = parser.floatValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, VERSION_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, VERSION_FIELD)) { version = parser.booleanValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, EXPLAIN_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, EXPLAIN_FIELD)) { explain = parser.booleanValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, TRACK_SCORES_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, TRACK_SCORES_FIELD)) { trackScores = parser.booleanValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { fetchSourceContext = FetchSourceContext.parse(context); - } else if (context.parseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { field(parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SORT_FIELD)) { sort(parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, PROFILE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, PROFILE_FIELD)) { profile = parser.booleanValue(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { queryBuilder = context.parseInnerQueryBuilder(); - } else if (context.parseFieldMatcher().match(currentFieldName, POST_FILTER_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, POST_FILTER_FIELD)) { postQueryBuilder = context.parseInnerQueryBuilder(); - } else if (context.parseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { fetchSourceContext = FetchSourceContext.parse(context); - } else if (context.parseFieldMatcher().match(currentFieldName, SCRIPT_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SCRIPT_FIELDS_FIELD)) { scriptFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { scriptFields.add(new ScriptField(context)); } - } else if (context.parseFieldMatcher().match(currentFieldName, INDICES_BOOST_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, INDICES_BOOST_FIELD)) { indexBoost = new ObjectFloatHashMap(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { @@ -1047,17 +1047,17 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ parser.getTokenLocation()); } } - } else if (context.parseFieldMatcher().match(currentFieldName, AGGREGATIONS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, AGGREGATIONS_FIELD)) { aggregations = aggParsers.parseAggregators(context); - } else if (context.parseFieldMatcher().match(currentFieldName, HIGHLIGHT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, HIGHLIGHT_FIELD)) { highlightBuilder = HighlightBuilder.fromXContent(context); - } else if (context.parseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) { innerHitsBuilder = InnerHitsBuilder.fromXContent(context); - } else if (context.parseFieldMatcher().match(currentFieldName, SUGGEST_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SUGGEST_FIELD)) { suggestBuilder = SuggestBuilder.fromXContent(context, suggesters); - } else if (context.parseFieldMatcher().match(currentFieldName, SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SORT_FIELD)) { sorts = new ArrayList<>(SortBuilder.fromXContent(context)); - } else if (context.parseFieldMatcher().match(currentFieldName, EXT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, EXT_FIELD)) { XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().copyCurrentStructure(parser); ext = xContentBuilder.bytes(); } else { @@ -1066,7 +1066,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { fieldNames = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -1076,7 +1076,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); } } - } else if (context.parseFieldMatcher().match(currentFieldName, FIELDDATA_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDDATA_FIELDS_FIELD)) { fieldDataFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -1086,14 +1086,14 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); } } - } else if (context.parseFieldMatcher().match(currentFieldName, SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SORT_FIELD)) { sorts = new ArrayList<>(SortBuilder.fromXContent(context)); - } else if (context.parseFieldMatcher().match(currentFieldName, RESCORE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, RESCORE_FIELD)) { rescoreBuilders = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { rescoreBuilders.add(RescoreBuilder.parseFromXContent(context)); } - } else if (context.parseFieldMatcher().match(currentFieldName, STATS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, STATS_FIELD)) { stats = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -1103,10 +1103,10 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); } } - } else if (context.parseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { fetchSourceContext = FetchSourceContext.parse(context); - } else if (context.parseFieldMatcher().match(currentFieldName, SEARCH_AFTER)) { - searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.parseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, SEARCH_AFTER)) { + searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.getParseFieldMatcher()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); @@ -1305,17 +1305,17 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (context.parseFieldMatcher().match(currentFieldName, SCRIPT_FIELD)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (context.parseFieldMatcher().match(currentFieldName, IGNORE_FAILURE_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, IGNORE_FAILURE_FIELD)) { ignoreFailure = parser.booleanValue(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, SCRIPT_FIELD)) { - script = Script.parse(parser, context.parseFieldMatcher()); + if (context.getParseFieldMatcher().match(currentFieldName, SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); } 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/fetch/source/FetchSourceContext.java b/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceContext.java index 891a2f09ec6..658bb1d72ee 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceContext.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceContext.java @@ -169,7 +169,7 @@ public class FetchSourceContext implements Streamable, ToXContent { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, INCLUDES_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, INCLUDES_FIELD)) { List includesList = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -180,7 +180,7 @@ public class FetchSourceContext implements Streamable, ToXContent { } } includes = includesList.toArray(new String[includesList.size()]); - } else if (context.parseFieldMatcher().match(currentFieldName, EXCLUDES_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, EXCLUDES_FIELD)) { List excludesList = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -196,9 +196,9 @@ public class FetchSourceContext implements Streamable, ToXContent { parser.getTokenLocation()); } } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, INCLUDES_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, INCLUDES_FIELD)) { includes = new String[] {parser.text()}; - } else if (context.parseFieldMatcher().match(currentFieldName, EXCLUDES_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, EXCLUDES_FIELD)) { excludes = new String[] {parser.text()}; } } else { diff --git a/core/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java b/core/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java index ae85a4e3fae..5b33769af44 100644 --- a/core/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java @@ -85,7 +85,7 @@ public abstract class RescoreBuilder> extends ToXC if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(fieldName, WINDOW_SIZE_FIELD)) { + if (parseContext.getParseFieldMatcher().match(fieldName, WINDOW_SIZE_FIELD)) { windowSize = parser.intValue(); } else { throw new ParsingException(parser.getTokenLocation(), "rescore doesn't support [" + fieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java index 21acd2b6c45..dfced1d8f57 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java @@ -337,17 +337,17 @@ public class FieldSortBuilder extends SortBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, NESTED_FILTER)) { + if (context.getParseFieldMatcher().match(currentFieldName, NESTED_FILTER)) { nestedFilter = context.parseInnerQueryBuilder(); } else { throw new ParsingException(parser.getTokenLocation(), "Expected " + NESTED_FILTER.getPreferredName() + " element."); } } else if (token.isValue()) { - if (context.parseFieldMatcher().match(currentFieldName, NESTED_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, NESTED_PATH)) { nestedPath = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, MISSING)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, MISSING)) { missing = parser.objectText(); - } else if (context.parseFieldMatcher().match(currentFieldName, ORDER)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, ORDER)) { String sortOrder = parser.text(); if ("asc".equals(sortOrder)) { order = SortOrder.ASC; @@ -356,9 +356,9 @@ public class FieldSortBuilder extends SortBuilder { } else { throw new ParsingException(parser.getTokenLocation(), "Sort order [{}] not supported.", sortOrder); } - } else if (context.parseFieldMatcher().match(currentFieldName, SORT_MODE)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SORT_MODE)) { sortMode = SortMode.fromString(parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, UNMAPPED_TYPE)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, UNMAPPED_TYPE)) { unmappedType = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "Option [{}] not supported.", currentFieldName); diff --git a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java index d8878fed298..ef86c45afd8 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java @@ -407,7 +407,7 @@ public class GeoDistanceSortBuilder extends SortBuilder */ public static GeoDistanceSortBuilder fromXContent(QueryParseContext context, String elementName) throws IOException { XContentParser parser = context.parser(); - ParseFieldMatcher parseFieldMatcher = context.parseFieldMatcher(); + ParseFieldMatcher parseFieldMatcher = context.getParseFieldMatcher(); String fieldName = null; List geoPoints = new ArrayList<>(); DistanceUnit unit = DistanceUnit.DEFAULT; diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java index 7f0f07045a8..8267429f77c 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java @@ -84,7 +84,7 @@ public class ScoreSortBuilder extends SortBuilder { */ public static ScoreSortBuilder fromXContent(QueryParseContext context, String fieldName) throws IOException { XContentParser parser = context.parser(); - ParseFieldMatcher matcher = context.parseFieldMatcher(); + ParseFieldMatcher matcher = context.getParseFieldMatcher(); XContentParser.Token token; String currentName = parser.currentName(); 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 2751d497519..3e0314bda1b 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java @@ -231,7 +231,7 @@ public class ScriptSortBuilder extends SortBuilder { public static ScriptSortBuilder fromXContent(QueryParseContext context, String elementName) throws IOException { ScriptParameterParser scriptParameterParser = new ScriptParameterParser(); XContentParser parser = context.parser(); - ParseFieldMatcher parseField = context.parseFieldMatcher(); + ParseFieldMatcher parseField = context.getParseFieldMatcher(); Script script = null; ScriptSortType type = null; SortMode sortMode = null; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java index ff56f395a5c..b3493a9a66c 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java @@ -140,7 +140,7 @@ public class SuggestBuilder extends ToXContentToBytes implements Writeable> extends static SuggestionBuilder fromXContent(QueryParseContext parseContext, Suggesters suggesters) throws IOException { XContentParser parser = parseContext.parser(); - ParseFieldMatcher parsefieldMatcher = parseContext.parseFieldMatcher(); + ParseFieldMatcher parsefieldMatcher = parseContext.getParseFieldMatcher(); XContentParser.Token token; String currentFieldName = null; String suggestText = null; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/Laplace.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/Laplace.java index 15eb759f2ae..89b2e763540 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/Laplace.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/Laplace.java @@ -112,7 +112,7 @@ public final class Laplace extends SmoothingModel { if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); } - if (token.isValue() && parseContext.parseFieldMatcher().match(fieldName, ALPHA_FIELD)) { + if (token.isValue() && parseContext.getParseFieldMatcher().match(fieldName, ALPHA_FIELD)) { alpha = parser.doubleValue(); } } diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java index f351bebe5a8..ba25766c8e0 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java @@ -138,7 +138,7 @@ public final class LinearInterpolation extends SmoothingModel { double trigramLambda = 0.0; double bigramLambda = 0.0; double unigramLambda = 0.0; - ParseFieldMatcher matcher = parseContext.parseFieldMatcher(); + ParseFieldMatcher matcher = parseContext.getParseFieldMatcher(); while ((token = parser.nextToken()) != Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); 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 299c57d8d26..177e2b7d518 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 @@ -493,7 +493,7 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder, public static SmoothingModel fromXContent(QueryParseContext parseContext) throws IOException { XContentParser parser = parseContext.parser(); - ParseFieldMatcher parseFieldMatcher = parseContext.parseFieldMatcher(); + ParseFieldMatcher parseFieldMatcher = parseContext.getParseFieldMatcher(); XContentParser.Token token; String fieldName = null; SmoothingModel model = null; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/StupidBackoff.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/StupidBackoff.java index cf1c436640b..4160fcb42d4 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/StupidBackoff.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/StupidBackoff.java @@ -115,7 +115,7 @@ public final class StupidBackoff extends SmoothingModel { if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); } - if (token.isValue() && parseContext.parseFieldMatcher().match(fieldName, DISCOUNT_FIELD)) { + if (token.isValue() && parseContext.getParseFieldMatcher().match(fieldName, DISCOUNT_FIELD)) { discount = parser.doubleValue(); } } diff --git a/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java index 0676bbf8594..41a6e61301c 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java @@ -392,7 +392,7 @@ public class TermSuggestionBuilder extends SuggestionBuilder sourceParser.parse(p, v.getSearchRequest(), c), 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.queryParseContext.parseFieldMatcher())), new ParseField("script"), + PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.queryParseContext.getParseFieldMatcher())), new ParseField("script"), ValueType.OBJECT); PARSER.declareString(ReindexRequest::setConflicts, new ParseField("conflicts")); } @@ -185,7 +185,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler