Throw parsing error if prefix query contains multiple fields in its short version
This commit is contained in:
parent
040f9c6be6
commit
8f485b3614
|
@ -158,6 +158,10 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder>
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (fieldName != null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[prefix] query doesn't support multiple fields, found ["
|
||||
+ fieldName + "] and [" + parser.currentName() + "]");
|
||||
}
|
||||
fieldName = currentFieldName;
|
||||
value = parser.textOrNull();
|
||||
}
|
||||
|
|
|
@ -127,5 +127,15 @@ public class PrefixQueryBuilderTests extends AbstractQueryTestCase<PrefixQueryBu
|
|||
"}";
|
||||
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
|
||||
assertEquals("[prefix] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
|
||||
|
||||
String shortJson =
|
||||
"{\n" +
|
||||
" \"prefix\": {\n" +
|
||||
" \"user1\": \"ki\",\n" +
|
||||
" \"user2\": \"ki\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
|
||||
assertEquals("[prefix] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue