Throw parsing error if span term query contains multiple fields in its short version
This commit is contained in:
parent
d4db987825
commit
0f54cb69ab
|
@ -104,10 +104,7 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuil
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (fieldName != null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[span_term] query doesn't support multiple fields, found ["
|
||||
+ fieldName + "] and [" + currentFieldName + "]");
|
||||
}
|
||||
throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
|
||||
fieldName = currentFieldName;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
|
@ -128,6 +125,7 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuil
|
|||
}
|
||||
}
|
||||
} else {
|
||||
throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
|
||||
fieldName = parser.currentName();
|
||||
value = parser.objectBytes();
|
||||
}
|
||||
|
|
|
@ -120,6 +120,15 @@ public class SpanTermQueryBuilderTests extends AbstractTermQueryTestCase<SpanTer
|
|||
"}";
|
||||
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
|
||||
assertEquals("[span_term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
|
||||
|
||||
String shortJson = "{\n" +
|
||||
" \"span_term\" : {\n" +
|
||||
" \"message1\" : \"this\",\n" +
|
||||
" \"message2\" : \"this\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
|
||||
assertEquals("[span_term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue