diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsParser.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsParser.java index 1db49b50b88..fd13037e8f9 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsParser.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsParser.java @@ -39,7 +39,7 @@ public class MatrixStatsParser extends NumericValuesSourceParser { @Override protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser, Map otherOptions) throws IOException { - if (MULTIVALUE_MODE_FIELD.match(currentFieldName)) { + if (MULTIVALUE_MODE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { if (token == XContentParser.Token.VALUE_STRING) { otherOptions.put(MULTIVALUE_MODE_FIELD, parser.text()); return true; diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceParser.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceParser.java index bd265f5ead3..22a90b552d9 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceParser.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceParser.java @@ -88,11 +88,11 @@ public abstract class MultiValuesSourceParser implement if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (CommonFields.FIELDS.match(currentFieldName)) { + if (CommonFields.FIELDS.match(currentFieldName, parser.getDeprecationHandler())) { fields = Collections.singletonList(parser.text()); - } else if (formattable && CommonFields.FORMAT.match(currentFieldName)) { + } else if (formattable && CommonFields.FORMAT.match(currentFieldName, parser.getDeprecationHandler())) { format = parser.text(); - } else if (CommonFields.VALUE_TYPE.match(currentFieldName)) { + } else if (CommonFields.VALUE_TYPE.match(currentFieldName, parser.getDeprecationHandler())) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]. " + "Multi-field aggregations do not support scripts."); @@ -101,12 +101,12 @@ public abstract class MultiValuesSourceParser implement "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } } else if (token == XContentParser.Token.START_OBJECT) { - if (CommonFields.MISSING.match(currentFieldName)) { + if (CommonFields.MISSING.match(currentFieldName, parser.getDeprecationHandler())) { missingMap = new HashMap<>(); while (parser.nextToken() != XContentParser.Token.END_OBJECT) { parseMissingAndAdd(aggregationName, currentFieldName, parser, missingMap); } - } else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { + } else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]. " + "Multi-field aggregations do not support scripts."); @@ -116,11 +116,11 @@ public abstract class MultiValuesSourceParser implement "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) { + if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]. " + "Multi-field aggregations do not support scripts."); - } else if (CommonFields.FIELDS.match(currentFieldName)) { + } else if (CommonFields.FIELDS.match(currentFieldName, parser.getDeprecationHandler())) { fields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java b/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java index dbbb98af65a..65a02b9c83e 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java @@ -257,27 +257,27 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder entry = itr.next(); String parameterName = entry.getKey(); Object parameterValue = entry.getValue(); - if (Script.LANG_PARSE_FIELD.match(parameterName)) { + if (Script.LANG_PARSE_FIELD.match(parameterName, LoggingDeprecationHandler.INSTANCE)) { if (parameterValue instanceof String || parameterValue == null) { lang = (String) parameterValue; } else { throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); } - } else if (Script.PARAMS_PARSE_FIELD.match(parameterName)) { + } else if (Script.PARAMS_PARSE_FIELD.match(parameterName, LoggingDeprecationHandler.INSTANCE)) { if (parameterValue instanceof Map || parameterValue == null) { params = (Map) parameterValue; } else { throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); } - } else if (ScriptType.INLINE.getParseField().match(parameterName)) { + } else if (ScriptType.INLINE.getParseField().match(parameterName, LoggingDeprecationHandler.INSTANCE)) { if (parameterValue instanceof String || parameterValue == null) { script = (String) parameterValue; type = ScriptType.INLINE; } else { throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]"); } - } else if (ScriptType.STORED.getParseField().match(parameterName)) { + } else if (ScriptType.STORED.getParseField().match(parameterName, LoggingDeprecationHandler.INSTANCE)) { if (parameterValue instanceof String || parameterValue == null) { script = (String) parameterValue; type = ScriptType.STORED; diff --git a/server/src/test/java/org/elasticsearch/common/ParseFieldTests.java b/server/src/test/java/org/elasticsearch/common/ParseFieldTests.java index ab70bd6ecae..72ba5578a49 100644 --- a/server/src/test/java/org/elasticsearch/common/ParseFieldTests.java +++ b/server/src/test/java/org/elasticsearch/common/ParseFieldTests.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.common; +import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.test.ESTestCase; import static org.hamcrest.CoreMatchers.is; @@ -32,16 +33,16 @@ public class ParseFieldTests extends ESTestCase { String[] deprecated = new String[]{"barFoo", "bar_foo", "Foobar"}; ParseField withDeprecations = field.withDeprecation(deprecated); assertThat(field, not(sameInstance(withDeprecations))); - assertThat(field.match(name), is(true)); - assertThat(field.match("foo bar"), is(false)); + assertThat(field.match(name, LoggingDeprecationHandler.INSTANCE), is(true)); + assertThat(field.match("foo bar", LoggingDeprecationHandler.INSTANCE), is(false)); for (String deprecatedName : deprecated) { - assertThat(field.match(deprecatedName), is(false)); + assertThat(field.match(deprecatedName, LoggingDeprecationHandler.INSTANCE), is(false)); } - assertThat(withDeprecations.match(name), is(true)); - assertThat(withDeprecations.match("foo bar"), is(false)); + assertThat(withDeprecations.match(name, LoggingDeprecationHandler.INSTANCE), is(true)); + assertThat(withDeprecations.match("foo bar", LoggingDeprecationHandler.INSTANCE), is(false)); for (String deprecatedName : deprecated) { - assertThat(withDeprecations.match(deprecatedName), is(true)); + assertThat(withDeprecations.match(deprecatedName, LoggingDeprecationHandler.INSTANCE), is(true)); assertWarnings("Deprecated field [" + deprecatedName + "] used, expected [foo_bar] instead"); } } @@ -50,12 +51,12 @@ public class ParseFieldTests extends ESTestCase { String name = "like_text"; String[] deprecated = new String[]{"text", "same_as_text"}; ParseField field = new ParseField(name).withDeprecation(deprecated).withAllDeprecated("like"); - assertFalse(field.match("not a field name")); - assertTrue(field.match("text")); + assertFalse(field.match("not a field name", LoggingDeprecationHandler.INSTANCE)); + assertTrue(field.match("text", LoggingDeprecationHandler.INSTANCE)); assertWarnings("Deprecated field [text] used, replaced by [like]"); - assertTrue(field.match("same_as_text")); + assertTrue(field.match("same_as_text", LoggingDeprecationHandler.INSTANCE)); assertWarnings("Deprecated field [same_as_text] used, replaced by [like]"); - assertTrue(field.match("like_text")); + assertTrue(field.match("like_text", LoggingDeprecationHandler.INSTANCE)); assertWarnings("Deprecated field [like_text] used, replaced by [like]"); } diff --git a/server/src/test/java/org/elasticsearch/search/SearchModuleTests.java b/server/src/test/java/org/elasticsearch/search/SearchModuleTests.java index 0b69a9bd65d..ca5efe02367 100644 --- a/server/src/test/java/org/elasticsearch/search/SearchModuleTests.java +++ b/server/src/test/java/org/elasticsearch/search/SearchModuleTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.common.inject.ModuleTestCase; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -187,13 +188,17 @@ public class SearchModuleTests extends ModuleTestCase { } })); assertEquals(1, module.getNamedXContents().stream() - .filter(e -> e.categoryClass.equals(SuggestionBuilder.class) && e.name.match("term")).count()); + .filter(e -> e.categoryClass.equals(SuggestionBuilder.class) && + e.name.match("term", LoggingDeprecationHandler.INSTANCE)).count()); assertEquals(1, module.getNamedXContents().stream() - .filter(e -> e.categoryClass.equals(SuggestionBuilder.class) && e.name.match("phrase")).count()); + .filter(e -> e.categoryClass.equals(SuggestionBuilder.class) && + e.name.match("phrase", LoggingDeprecationHandler.INSTANCE)).count()); assertEquals(1, module.getNamedXContents().stream() - .filter(e -> e.categoryClass.equals(SuggestionBuilder.class) && e.name.match("completion")).count()); + .filter(e -> e.categoryClass.equals(SuggestionBuilder.class) && + e.name.match("completion", LoggingDeprecationHandler.INSTANCE)).count()); assertEquals(1, module.getNamedXContents().stream() - .filter(e -> e.categoryClass.equals(SuggestionBuilder.class) && e.name.match("custom")).count()); + .filter(e -> e.categoryClass.equals(SuggestionBuilder.class) && + e.name.match("custom", LoggingDeprecationHandler.INSTANCE)).count()); assertEquals(1, module.getNamedWriteables().stream() .filter(e -> e.categoryClass.equals(SuggestionBuilder.class) && e.name.equals("term")).count()); @@ -250,7 +255,8 @@ public class SearchModuleTests extends ModuleTestCase { assertThat( module.getNamedXContents().stream() - .filter(entry -> entry.categoryClass.equals(BaseAggregationBuilder.class) && entry.name.match("test")) + .filter(entry -> entry.categoryClass.equals(BaseAggregationBuilder.class) && + entry.name.match("test", LoggingDeprecationHandler.INSTANCE)) .collect(toList()), hasSize(1)); } @@ -266,7 +272,8 @@ public class SearchModuleTests extends ModuleTestCase { assertThat( module.getNamedXContents().stream() - .filter(entry -> entry.categoryClass.equals(BaseAggregationBuilder.class) && entry.name.match("test")) + .filter(entry -> entry.categoryClass.equals(BaseAggregationBuilder.class) && + entry.name.match("test", LoggingDeprecationHandler.INSTANCE)) .collect(toList()), hasSize(1)); } @@ -280,7 +287,8 @@ public class SearchModuleTests extends ModuleTestCase { })); assertThat( module.getNamedXContents().stream() - .filter(entry -> entry.categoryClass.equals(RescorerBuilder.class) && entry.name.match("test")) + .filter(entry -> entry.categoryClass.equals(RescorerBuilder.class) && + entry.name.match("test", LoggingDeprecationHandler.INSTANCE)) .collect(toList()), hasSize(1)); } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/support/IncludeExcludeTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/support/IncludeExcludeTests.java index 48a4b15cd09..6e477021a54 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/support/IncludeExcludeTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/support/IncludeExcludeTests.java @@ -268,10 +268,10 @@ public class IncludeExcludeTests extends ESTestCase { IncludeExclude exc = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { assertEquals(XContentParser.Token.FIELD_NAME, token); - if (IncludeExclude.INCLUDE_FIELD.match(parser.currentName())) { + if (IncludeExclude.INCLUDE_FIELD.match(parser.currentName(), parser.getDeprecationHandler())) { token = parser.nextToken(); inc = IncludeExclude.parseInclude(parser); - } else if (IncludeExclude.EXCLUDE_FIELD.match(parser.currentName())) { + } else if (IncludeExclude.EXCLUDE_FIELD.match(parser.currentName(), parser.getDeprecationHandler())) { token = parser.nextToken(); exc = IncludeExclude.parseExclude(parser); } else { diff --git a/server/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterSearchIT.java b/server/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterSearchIT.java index d5eee4d3dee..a6040a0c65f 100644 --- a/server/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterSearchIT.java +++ b/server/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterSearchIT.java @@ -160,15 +160,15 @@ public class CustomSuggesterSearchIT extends ESIntegTestCase { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (SuggestionBuilder.ANALYZER_FIELD.match(currentFieldName)) { + if (SuggestionBuilder.ANALYZER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { analyzer = parser.text(); - } else if (SuggestionBuilder.FIELDNAME_FIELD.match(currentFieldName)) { + } else if (SuggestionBuilder.FIELDNAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { fieldname = parser.text(); - } else if (SuggestionBuilder.SIZE_FIELD.match(currentFieldName)) { + } else if (SuggestionBuilder.SIZE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { sizeField = parser.intValue(); - } else if (SuggestionBuilder.SHARDSIZE_FIELD.match(currentFieldName)) { + } else if (SuggestionBuilder.SHARDSIZE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { shardSize = parser.intValue(); - } else if (RANDOM_SUFFIX_FIELD.match(currentFieldName)) { + } else if (RANDOM_SUFFIX_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { suffix = parser.text(); } } else { diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index ccf32345f99..aaed939c310 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -65,6 +65,7 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.MockBigArrays; import org.elasticsearch.common.util.MockPageCacheRecycler; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContent; @@ -1093,35 +1094,36 @@ public abstract class ESTestCase extends LuceneTestCase { * Create a new {@link XContentParser}. */ protected final XContentParser createParser(XContentBuilder builder) throws IOException { - return builder.generator().contentType().xContent().createParser(xContentRegistry(), builder.bytes()); + return builder.generator().contentType().xContent() + .createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, builder.bytes()); } /** * Create a new {@link XContentParser}. */ protected final XContentParser createParser(XContent xContent, String data) throws IOException { - return xContent.createParser(xContentRegistry(), data); + return xContent.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, data); } /** * Create a new {@link XContentParser}. */ protected final XContentParser createParser(XContent xContent, InputStream data) throws IOException { - return xContent.createParser(xContentRegistry(), data); + return xContent.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, data); } /** * Create a new {@link XContentParser}. */ protected final XContentParser createParser(XContent xContent, byte[] data) throws IOException { - return xContent.createParser(xContentRegistry(), data); + return xContent.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, data); } /** * Create a new {@link XContentParser}. */ protected final XContentParser createParser(XContent xContent, BytesReference data) throws IOException { - return xContent.createParser(xContentRegistry(), data); + return xContent.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, data); } /**