diff --git a/core/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java b/core/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java index 1eec405502ee5..e8eed77969887 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java @@ -27,6 +27,8 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -45,6 +47,8 @@ */ public class FetchSourceContext implements Writeable, ToXContent { + private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(ParseField.class)); + public static final ParseField INCLUDES_FIELD = new ParseField("includes", "include"); public static final ParseField EXCLUDES_FIELD = new ParseField("excludes", "exclude"); @@ -148,7 +152,7 @@ public static FetchSourceContext fromXContent(XContentParser parser, ParseFieldM if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_ARRAY) { - if (parseFieldMatcher.match(currentFieldName, INCLUDES_FIELD)) { + if ("includes".equals(currentFieldName) || "include".equals(currentFieldName)){ List includesList = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -159,6 +163,9 @@ public static FetchSourceContext fromXContent(XContentParser parser, ParseFieldM } } includes = includesList.toArray(new String[includesList.size()]); + if ("include".equals(currentFieldName)){ + DEPRECATION_LOGGER.deprecated("Deprecated field [include] used, expected [includes] instead"); + } } else if (parseFieldMatcher.match(currentFieldName, EXCLUDES_FIELD)) { List excludesList = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { @@ -175,8 +182,11 @@ public static FetchSourceContext fromXContent(XContentParser parser, ParseFieldM + " in [" + currentFieldName + "].", parser.getTokenLocation()); } } else if (token == XContentParser.Token.VALUE_STRING) { - if (parseFieldMatcher.match(currentFieldName, INCLUDES_FIELD)) { + if ("includes".equals(currentFieldName) || "include".equals(currentFieldName)) { includes = new String[] {parser.text()}; + if ("include".equals(currentFieldName)){ + DEPRECATION_LOGGER.deprecated("Deprecated field [include] used, expected [includes] instead"); + } } else if (parseFieldMatcher.match(currentFieldName, EXCLUDES_FIELD)) { excludes = new String[] {parser.text()}; } else {