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

This commit is contained in:
javanna 2016-08-08 19:40:23 +02:00 committed by Luca Cavanna
parent 329eaaea65
commit 1db3c67e31
2 changed files with 13 additions and 0 deletions

View File

@ -345,6 +345,10 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
} }
} }
} else { } else {
if (fieldName != null) {
throw new ParsingException(parser.getTokenLocation(), "[common] query doesn't support multiple fields, found ["
+ fieldName + "] and [" + parser.currentName() + "]");
}
fieldName = parser.currentName(); fieldName = parser.currentName();
text = parser.objectText(); text = parser.objectText();
} }

View File

@ -194,5 +194,14 @@ public class CommonTermsQueryBuilderTests extends AbstractQueryTestCase<CommonTe
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json)); ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[common] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage()); assertEquals("[common] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" +
" \"common\" : {\n" +
" \"message1\" : \"nelly the elephant not as a cartoon\",\n" +
" \"message2\" : \"nelly the elephant not as a cartoon\"\n" +
" }\n" +
"}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[common] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
} }
} }