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

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

View File

@ -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();
}

View File

@ -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());
}
}