FuzzyQueryBuilder should error when parsing array of values (#23762)
Closes #23759
This commit is contained in:
parent
4f694a3312
commit
fc8cb417e7
|
@ -275,7 +275,7 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
} else if (token.isValue()) {
|
||||
if (TERM_FIELD.match(currentFieldName)) {
|
||||
value = parser.objectBytes();
|
||||
} else if (VALUE_FIELD.match(currentFieldName)) {
|
||||
|
@ -298,6 +298,9 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
|||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"[fuzzy] query does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"[" + NAME + "] unexpected token [" + token + "] after [" + currentFieldName + "]");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -190,4 +190,17 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
|
|||
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
|
||||
assertEquals("[fuzzy] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
|
||||
}
|
||||
|
||||
public void testParseFailsWithValueArray() {
|
||||
String query = "{\n" +
|
||||
" \"fuzzy\" : {\n" +
|
||||
" \"message1\" : {\n" +
|
||||
" \"value\" : [ \"one\", \"two\", \"three\"]\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(query));
|
||||
assertEquals("[fuzzy] unexpected token [START_ARRAY] after [value]", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue