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

This commit is contained in:
javanna 2016-08-08 19:40:54 +02:00 committed by Luca Cavanna
parent 1db3c67e31
commit 5d238e86f6
2 changed files with 14 additions and 0 deletions

View File

@ -309,6 +309,10 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
}
}
} else {
if (fieldName != null) {
throw new ParsingException(parser.getTokenLocation(), "[fuzzy] query doesn't support multiple fields, found ["
+ fieldName + "] and [" + parser.currentName() + "]");
}
fieldName = parser.currentName();
value = parser.objectBytes();
}

View File

@ -169,5 +169,15 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[fuzzy] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" +
" \"fuzzy\" : {\n" +
" \"message1\" : \"this is a test\",\n" +
" \"message2\" : \"value\" : \"this is a test\"\n" +
" }\n" +
"}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[fuzzy] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
}
}