diff --git a/core/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java index 982b5231b42..c2ad9983290 100644 --- a/core/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java @@ -102,7 +102,7 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException { XContentParser parser = parseContext.parser(); - XContentParser.Token token = parser.nextToken(); - if (token != XContentParser.Token.FIELD_NAME) { - throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query malformed, no field"); - } - String fieldName = parser.currentName(); + + String fieldName = null; Object text = null; float boost = AbstractQueryBuilder.DEFAULT_BOOST; String analyzer = null; @@ -280,78 +277,79 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder getAlternateVersions() { + Map alternateVersions = new HashMap<>(); + CommonTermsQueryBuilder commonTermsQuery = new CommonTermsQueryBuilder(randomAsciiOfLengthBetween(1, 10), + randomAsciiOfLengthBetween(1, 10)); + String contentString = "{\n" + + " \"common\" : {\n" + + " \"" + commonTermsQuery.fieldName() + "\" : \"" + commonTermsQuery.value() + "\"\n" + + " }\n" + + "}"; + alternateVersions.put(contentString, commonTermsQuery); + return alternateVersions; + } + @Override protected void doAssertLuceneQuery(CommonTermsQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { assertThat(query, instanceOf(ExtendedCommonTermsQuery.class)); @@ -98,14 +115,14 @@ public class CommonTermsQueryBuilderTests extends AbstractQueryTestCase