Skip to content

Commit 2c6ad4d

Browse files
authored
Merge pull request #168 from hesamemadi/fix-source-filtering-names-inconsistency
Ticket elastic#22792, fixed inconsistency between query parameters vs request body
2 parents 8b45104 + 74aa370 commit 2c6ad4d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.elasticsearch.common.io.stream.StreamInput;
2828
import org.elasticsearch.common.io.stream.StreamOutput;
2929
import org.elasticsearch.common.io.stream.Writeable;
30+
import org.elasticsearch.common.logging.DeprecationLogger;
31+
import org.elasticsearch.common.logging.Loggers;
3032
import org.elasticsearch.common.xcontent.ToXContent;
3133
import org.elasticsearch.common.xcontent.XContentBuilder;
3234
import org.elasticsearch.common.xcontent.XContentParser;
@@ -45,6 +47,8 @@
4547
*/
4648
public class FetchSourceContext implements Writeable, ToXContent {
4749

50+
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(ParseField.class));
51+
4852
public static final ParseField INCLUDES_FIELD = new ParseField("includes", "include");
4953
public static final ParseField EXCLUDES_FIELD = new ParseField("excludes", "exclude");
5054

@@ -148,7 +152,7 @@ public static FetchSourceContext fromXContent(XContentParser parser, ParseFieldM
148152
if (token == XContentParser.Token.FIELD_NAME) {
149153
currentFieldName = parser.currentName();
150154
} else if (token == XContentParser.Token.START_ARRAY) {
151-
if (parseFieldMatcher.match(currentFieldName, INCLUDES_FIELD)) {
155+
if ("includes".equals(currentFieldName) || "include".equals(currentFieldName)){
152156
List<String> includesList = new ArrayList<>();
153157
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
154158
if (token == XContentParser.Token.VALUE_STRING) {
@@ -159,6 +163,9 @@ public static FetchSourceContext fromXContent(XContentParser parser, ParseFieldM
159163
}
160164
}
161165
includes = includesList.toArray(new String[includesList.size()]);
166+
if ("include".equals(currentFieldName)){
167+
DEPRECATION_LOGGER.deprecated("Deprecated field [include] used, expected [includes] instead");
168+
}
162169
} else if (parseFieldMatcher.match(currentFieldName, EXCLUDES_FIELD)) {
163170
List<String> excludesList = new ArrayList<>();
164171
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
@@ -175,8 +182,11 @@ public static FetchSourceContext fromXContent(XContentParser parser, ParseFieldM
175182
+ " in [" + currentFieldName + "].", parser.getTokenLocation());
176183
}
177184
} else if (token == XContentParser.Token.VALUE_STRING) {
178-
if (parseFieldMatcher.match(currentFieldName, INCLUDES_FIELD)) {
185+
if ("includes".equals(currentFieldName) || "include".equals(currentFieldName)) {
179186
includes = new String[] {parser.text()};
187+
if ("include".equals(currentFieldName)){
188+
DEPRECATION_LOGGER.deprecated("Deprecated field [include] used, expected [includes] instead");
189+
}
180190
} else if (parseFieldMatcher.match(currentFieldName, EXCLUDES_FIELD)) {
181191
excludes = new String[] {parser.text()};
182192
} else {

0 commit comments

Comments
 (0)