Throw parsing error if regexp query contains multiple fields in its short version
This commit is contained in:
parent
8f485b3614
commit
796bc74163
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue