diff --git a/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java index b868a2946efcc..81eacc6be414f 100644 --- a/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java @@ -110,6 +110,7 @@ public TermsQueryBuilder(String fieldName, TermsLookup termsLookup) { this.fieldName = fieldName; this.values = values == null ? null : convert(values); this.termsLookup = termsLookup; + this.rewrite_override = rewrite_override; this.supplier = null; } @@ -425,18 +426,13 @@ public static TermsQueryBuilder fromXContent(XContentParser parser) throws IOExc } fieldName = currentFieldName; termsLookup = TermsLookup.parseTermsLookup(parser); - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) { - rewrite_override = parser.textOrNull(); - } - } } else if (token.isValue()) { if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { boost = parser.floatValue(); } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { queryName = parser.text(); + } else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) { + rewrite_override = parser.textOrNull(); } else { throw new ParsingException( parser.getTokenLocation(),