Skip to content

Commit

Permalink
Merge pull request #168 from hesamemadi/fix-source-filtering-names-in…
Browse files Browse the repository at this point in the history
…consistency

Ticket elastic#22792, fixed inconsistency between query parameters vs request body
  • Loading branch information
kblincoe authored Apr 4, 2017
2 parents 8b45104 + 74aa370 commit 2c6ad4d
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");

Expand Down Expand Up @@ -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<String> includesList = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
if (token == XContentParser.Token.VALUE_STRING) {
Expand All @@ -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<String> excludesList = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
Expand All @@ -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 {
Expand Down

0 comments on commit 2c6ad4d

Please sign in to comment.