Throw parsing error if wildcard query contains multiple fields in its short version

This commit is contained in:
javanna 2016-08-08 19:42:48 +02:00 committed by Luca Cavanna
parent 796bc74163
commit 27a6983646
2 changed files with 14 additions and 0 deletions

View File

@ -174,6 +174,10 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder<WildcardQueryBuil
}
}
} else {
if (fieldName != null) {
throw new ParsingException(parser.getTokenLocation(), "[wildcard] query doesn't support multiple fields, found ["
+ fieldName + "] and [" + parser.currentName() + "]");
}
fieldName = parser.currentName();
value = parser.text();
}

View File

@ -113,5 +113,15 @@ public class WildcardQueryBuilderTests extends AbstractQueryTestCase<WildcardQue
"}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[wildcard] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
String shortJson =
"{\n" +
" \"wildcard\": {\n" +
" \"user1\": \"ki*y\",\n" +
" \"user2\": \"ki*y\"\n" +
" }\n" +
"}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[wildcard] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
}
}