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)) {
|
} else if (parseContext.isDeprecatedSetting(currentFieldName)) {
|
||||||
// skip
|
// skip
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
// also support a format of "term" : {"field_name" : { ... }}
|
throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
|
||||||
if (fieldName != null) {
|
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
|
||||||
"[term] query does not support different field names, use [bool] query instead");
|
|
||||||
}
|
|
||||||
fieldName = currentFieldName;
|
fieldName = currentFieldName;
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
|
@ -123,10 +119,7 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if (fieldName != null) {
|
throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
|
||||||
throw new ParsingException(parser.getTokenLocation(),
|
|
||||||
"[term] query does not support different field names, use [bool] query instead");
|
|
||||||
}
|
|
||||||
fieldName = currentFieldName;
|
fieldName = currentFieldName;
|
||||||
value = parser.objectBytes();
|
value = parser.objectBytes();
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
|
|
|
@ -154,7 +154,7 @@ public class TermQueryBuilderTests extends AbstractTermQueryTestCase<TermQueryBu
|
||||||
" }\n" +
|
" }\n" +
|
||||||
"}";
|
"}";
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
|
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" +
|
String shortJson = "{\n" +
|
||||||
" \"term\" : {\n" +
|
" \"term\" : {\n" +
|
||||||
|
@ -163,6 +163,6 @@ public class TermQueryBuilderTests extends AbstractTermQueryTestCase<TermQueryBu
|
||||||
" }\n" +
|
" }\n" +
|
||||||
"}";
|
"}";
|
||||||
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
|
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