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

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

View File

@ -229,6 +229,10 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
if (parseContext.getParseFieldMatcher().match(currentFieldName, NAME_FIELD)) {
queryName = parser.text();
} else {
if (fieldName != null) {
throw new ParsingException(parser.getTokenLocation(), "[regexp] query doesn't support multiple fields, found ["
+ fieldName + "] and [" + parser.currentName() + "]");
}
fieldName = currentFieldName;
value = parser.textOrNull();
}

View File

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