Modify term query error when multiple fields are provided to comply with all other queries
This commit is contained in:
parent
0f54cb69ab
commit
f9a40344b2
|
@ -98,11 +98,7 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> {
|
|||
} else if (parseContext.isDeprecatedSetting(currentFieldName)) {
|
||||
// skip
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
// also support a format of "term" : {"field_name" : { ... }}
|
||||
if (fieldName != null) {
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"[term] query does not support different field names, use [bool] query instead");
|
||||
}
|
||||
throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
|
||||
fieldName = currentFieldName;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
|
@ -123,10 +119,7 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> {
|
|||
}
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if (fieldName != null) {
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"[term] query does not support different field names, use [bool] query instead");
|
||||
}
|
||||
throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
|
||||
fieldName = currentFieldName;
|
||||
value = parser.objectBytes();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
|
|
|
@ -154,7 +154,7 @@ public class TermQueryBuilderTests extends AbstractTermQueryTestCase<TermQueryBu
|
|||
" }\n" +
|
||||
"}";
|
||||
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
|
||||
assertEquals("[term] query does not support different field names, use [bool] query instead", e.getMessage());
|
||||
assertEquals("[term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
|
||||
|
||||
String shortJson = "{\n" +
|
||||
" \"term\" : {\n" +
|
||||
|
@ -163,6 +163,6 @@ public class TermQueryBuilderTests extends AbstractTermQueryTestCase<TermQueryBu
|
|||
" }\n" +
|
||||
"}";
|
||||
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
|
||||
assertEquals("[term] query does not support different field names, use [bool] query instead", e.getMessage());
|
||||
assertEquals("[term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue