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

This commit is contained in:
javanna 2016-08-08 19:42:01 +02:00 committed by Luca Cavanna
parent cb41f304f2
commit d5316b2783
2 changed files with 13 additions and 0 deletions

View File

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

View File

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