Browse Source

Remove parse field deprecations in query builders (#26711)

The `fielddata` field and the use of the `_name` field in the short syntax of the range 
query have been deprecated in 5.0 and can be removed.

The same goes for the deprecated `score_mode` field in HasParentQueryBuilder,
the deprecated `like_text`, `ids` and `docs` parameter in the `more_like_this` query,
the deprecated query name in the short version of the `regexp` query, and several
deprecated alternative field names in other query builders.
Christoph Büscher 8 years ago
parent
commit
86b00b84bc
17 changed files with 19 additions and 126 deletions
  1. 1 1
      core/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java
  2. 1 1
      core/src/main/java/org/elasticsearch/index/query/MatchPhraseQueryBuilder.java
  3. 2 21
      core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
  4. 1 1
      core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java
  5. 1 1
      core/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java
  6. 2 11
      core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java
  7. 3 9
      core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java
  8. 1 1
      core/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java
  9. 0 15
      core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java
  10. 1 1
      docs/reference/query-dsl/multi-term-rewrite.asciidoc
  11. 0 13
      docs/reference/query-dsl/prefix-query.asciidoc
  12. 2 2
      modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java
  13. 2 13
      modules/parent-join/src/main/java/org/elasticsearch/join/query/HasParentQueryBuilder.java
  14. 1 1
      modules/parent-join/src/main/java/org/elasticsearch/join/query/ParentIdQueryBuilder.java
  15. 0 17
      modules/parent-join/src/test/java/org/elasticsearch/join/query/HasParentQueryBuilderTests.java
  16. 0 17
      modules/parent-join/src/test/java/org/elasticsearch/join/query/LegacyHasParentQueryBuilderTests.java
  17. 1 1
      qa/query-builder-bwc/src/test/java/org/elasticsearch/bwc/QueryBuilderBWCIT.java

+ 1 - 1
core/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java

@@ -39,7 +39,7 @@ import java.util.Objects;
 public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScoreQueryBuilder> {
     public static final String NAME = "constant_score";
 
-    private static final ParseField INNER_QUERY_FIELD = new ParseField("filter", "query");
+    private static final ParseField INNER_QUERY_FIELD = new ParseField("filter");
 
     private final QueryBuilder filterBuilder;
 

+ 1 - 1
core/src/main/java/org/elasticsearch/index/query/MatchPhraseQueryBuilder.java

@@ -38,7 +38,7 @@ import java.util.Objects;
  */
 public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQueryBuilder> {
     public static final String NAME = "match_phrase";
-    public static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop");
+    public static final ParseField SLOP_FIELD = new ParseField("slop");
 
     private final String fieldName;
 

+ 2 - 21
core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java

@@ -96,15 +96,12 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
         ParseField FIELDS = new ParseField("fields");
         ParseField LIKE = new ParseField("like");
         ParseField UNLIKE = new ParseField("unlike");
-        ParseField LIKE_TEXT = new ParseField("like_text").withAllDeprecated("like");
-        ParseField IDS = new ParseField("ids").withAllDeprecated("like");
-        ParseField DOCS = new ParseField("docs").withAllDeprecated("like");
         ParseField MAX_QUERY_TERMS = new ParseField("max_query_terms");
         ParseField MIN_TERM_FREQ = new ParseField("min_term_freq");
         ParseField MIN_DOC_FREQ = new ParseField("min_doc_freq");
         ParseField MAX_DOC_FREQ = new ParseField("max_doc_freq");
-        ParseField MIN_WORD_LENGTH = new ParseField("min_word_length", "min_word_len");
-        ParseField MAX_WORD_LENGTH = new ParseField("max_word_length", "max_word_len");
+        ParseField MIN_WORD_LENGTH = new ParseField("min_word_length");
+        ParseField MAX_WORD_LENGTH = new ParseField("max_word_length");
         ParseField STOP_WORDS = new ParseField("stop_words");
         ParseField ANALYZER = new ParseField("analyzer");
         ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match");
@@ -846,8 +843,6 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
                     parseLikeField(parser, likeTexts, likeItems);
                 } else if (Field.UNLIKE.match(currentFieldName)) {
                     parseLikeField(parser, unlikeTexts, unlikeItems);
-                } else if (Field.LIKE_TEXT.match(currentFieldName)) {
-                    likeTexts.add(parser.text());
                 } else if (Field.MAX_QUERY_TERMS.match(currentFieldName)) {
                     maxQueryTerms = parser.intValue();
                 } else if (Field.MIN_TERM_FREQ.match(currentFieldName)) {
@@ -891,20 +886,6 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
                     while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                         parseLikeField(parser, unlikeTexts, unlikeItems);
                     }
-                } else if (Field.IDS.match(currentFieldName)) {
-                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
-                        if (!token.isValue()) {
-                            throw new IllegalArgumentException("ids array element should only contain ids");
-                        }
-                        likeItems.add(new Item(null, null, parser.text()));
-                    }
-                } else if (Field.DOCS.match(currentFieldName)) {
-                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
-                        if (token != XContentParser.Token.START_OBJECT) {
-                            throw new IllegalArgumentException("docs array element should include an object");
-                        }
-                        likeItems.add(Item.parse(parser, new Item()));
-                    }
                 } else if (Field.STOP_WORDS.match(currentFieldName)) {
                     stopWords = new ArrayList<>();
                     while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {

+ 1 - 1
core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java

@@ -58,7 +58,7 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
     public static final boolean DEFAULT_LENIENCY = MatchQuery.DEFAULT_LENIENCY;
     public static final MatchQuery.ZeroTermsQuery DEFAULT_ZERO_TERMS_QUERY = MatchQuery.DEFAULT_ZERO_TERMS_QUERY;
 
-    private static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop");
+    private static final ParseField SLOP_FIELD = new ParseField("slop");
     private static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query");
     private static final ParseField LENIENT_FIELD = new ParseField("lenient");
     private static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency");

+ 1 - 1
core/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java

@@ -43,7 +43,7 @@ import java.util.Objects;
 public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder> implements MultiTermQueryBuilder {
     public static final String NAME = "prefix";
 
-    private static final ParseField PREFIX_FIELD = new ParseField("value", "prefix");
+    private static final ParseField PREFIX_FIELD = new ParseField("value");
     private static final ParseField REWRITE_FIELD = new ParseField("rewrite");
 
     private final String fieldName;

+ 2 - 11
core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java

@@ -53,11 +53,8 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
     public static final boolean DEFAULT_INCLUDE_UPPER = true;
     public static final boolean DEFAULT_INCLUDE_LOWER = true;
 
-    private static final ParseField FIELDDATA_FIELD = new ParseField("fielddata").withAllDeprecated("[no replacement]");
-    private static final ParseField NAME_FIELD = new ParseField("_name")
-        .withAllDeprecated("query name is not supported in short version of range query");
-    public static final ParseField LTE_FIELD = new ParseField("lte", "le");
-    public static final ParseField GTE_FIELD = new ParseField("gte", "ge");
+    public static final ParseField LTE_FIELD = new ParseField("lte");
+    public static final ParseField GTE_FIELD = new ParseField("gte");
     public static final ParseField FROM_FIELD = new ParseField("from");
     public static final ParseField TO_FIELD = new ParseField("to");
     private static final ParseField INCLUDE_LOWER_FIELD = new ParseField("include_lower");
@@ -416,13 +413,7 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
                     }
                 }
             } else if (token.isValue()) {
-                if (NAME_FIELD.match(currentFieldName)) {
-                    queryName = parser.text();
-                } else if (FIELDDATA_FIELD.match(currentFieldName)) {
-                    // ignore
-                } else {
                     throw new ParsingException(parser.getTokenLocation(), "[range] query does not support [" + currentFieldName + "]");
-                }
             }
         }
 

+ 3 - 9
core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java

@@ -47,8 +47,6 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
     public static final int DEFAULT_FLAGS_VALUE = RegexpFlag.ALL.value();
     public static final int DEFAULT_MAX_DETERMINIZED_STATES = Operations.DEFAULT_MAX_DETERMINIZED_STATES;
 
-    private static final ParseField NAME_FIELD = new ParseField("_name")
-            .withAllDeprecated("query name is not supported in short version of regexp query");
     private static final ParseField FLAGS_VALUE_FIELD = new ParseField("flags_value");
     private static final ParseField MAX_DETERMINIZED_STATES_FIELD = new ParseField("max_determinized_states");
     private static final ParseField FLAGS_FIELD = new ParseField("flags");
@@ -219,13 +217,9 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
                     }
                 }
             } else {
-                if (NAME_FIELD.match(currentFieldName)) {
-                    queryName = parser.text();
-                } else {
-                    throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
-                    fieldName = currentFieldName;
-                    value = parser.textOrNull();
-                }
+                throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
+                fieldName = currentFieldName;
+                value = parser.textOrNull();
             }
         }
 

+ 1 - 1
core/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java

@@ -25,7 +25,7 @@ import org.elasticsearch.common.ParseField;
 
 public final class QueryParsers {
 
-    public static final ParseField CONSTANT_SCORE = new ParseField("constant_score", "constant_score_auto", "constant_score_filter");
+    public static final ParseField CONSTANT_SCORE = new ParseField("constant_score");
     public static final ParseField SCORING_BOOLEAN = new ParseField("scoring_boolean");
     public static final ParseField CONSTANT_SCORE_BOOLEAN = new ParseField("constant_score_boolean");
     public static final ParseField TOP_TERMS = new ParseField("top_terms_");

+ 0 - 15
core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java

@@ -382,21 +382,6 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
                 "  }\n" +
                 "}";
         assertNotNull(parseQuery(json));
-
-        final String deprecatedJson =
-                "{\n" +
-                "  \"range\" : {\n" +
-                "    \"timestamp\" : {\n" +
-                "      \"from\" : \"2015-01-01 00:00:00\",\n" +
-                "      \"to\" : \"now\",\n" +
-                "      \"boost\" : 1.0\n" +
-                "    },\n" +
-                "    \"_name\" : \"my_range\"\n" +
-                "  }\n" +
-                "}";
-
-        assertNotNull(parseQuery(deprecatedJson));
-        assertWarnings("Deprecated field [_name] used, replaced by [query name is not supported in short version of range query]");
     }
 
     public void testRewriteDateToMatchAll() throws IOException {

+ 1 - 1
docs/reference/query-dsl/multi-term-rewrite.asciidoc

@@ -19,7 +19,7 @@ boost.
 into a should clause in a boolean query, and keeps the scores as
 computed by the query. Note that typically such scores are meaningless
 to the user, and require non-trivial CPU to compute, so it's almost
-always better to use `constant_score_auto`. This rewrite method will hit
+always better to use `constant_score`. This rewrite method will hit
 too many clauses failure if it exceeds the boolean query limit (defaults
 to `1024`).
 * `constant_score_boolean`: Similar to `scoring_boolean` except scores

+ 0 - 13
docs/reference/query-dsl/prefix-query.asciidoc

@@ -28,19 +28,6 @@ GET /_search
 --------------------------------------------------
 // CONSOLE
 
-Or with the `prefix` deprecated[5.0.0, Use `value`] syntax:
-
-[source,js]
---------------------------------------------------
-GET /_search
-{ "query": {
-    "prefix" : { "user" :  { "prefix" : "ki", "boost" : 2.0 } }
-  }
-}
---------------------------------------------------
-// CONSOLE
-// TEST[warning:Deprecated field [prefix] used, expected [value] instead]
-
 This multi term query allows you to control how it gets rewritten using the
 <<query-dsl-multi-term-rewrite,rewrite>>
 parameter.

+ 2 - 2
modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java

@@ -76,8 +76,8 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
      */
     public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
 
-    private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
-    private static final ParseField TYPE_FIELD = new ParseField("type", "child_type");
+    private static final ParseField QUERY_FIELD = new ParseField("query");
+    private static final ParseField TYPE_FIELD = new ParseField("type");
     private static final ParseField MAX_CHILDREN_FIELD = new ParseField("max_children");
     private static final ParseField MIN_CHILDREN_FIELD = new ParseField("min_children");
     private static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode");

+ 2 - 13
modules/parent-join/src/main/java/org/elasticsearch/join/query/HasParentQueryBuilder.java

@@ -63,9 +63,8 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
      */
     public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
 
-    private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
-    private static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode").withAllDeprecated("score");
-    private static final ParseField TYPE_FIELD = new ParseField("parent_type", "type");
+    private static final ParseField QUERY_FIELD = new ParseField("query");
+    private static final ParseField TYPE_FIELD = new ParseField("parent_type");
     private static final ParseField SCORE_FIELD = new ParseField("score");
     private static final ParseField INNER_HITS_FIELD = new ParseField("inner_hits");
     private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");
@@ -307,16 +306,6 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
             } else if (token.isValue()) {
                 if (TYPE_FIELD.match(currentFieldName)) {
                     parentType = parser.text();
-                } else if (SCORE_MODE_FIELD.match(currentFieldName)) {
-                    String scoreModeValue = parser.text();
-                    if ("score".equals(scoreModeValue)) {
-                        score = true;
-                    } else if ("none".equals(scoreModeValue)) {
-                        score = false;
-                    } else {
-                        throw new ParsingException(parser.getTokenLocation(), "[has_parent] query does not support [" +
-                                scoreModeValue + "] as an option for score_mode");
-                    }
                 } else if (SCORE_FIELD.match(currentFieldName)) {
                     score = parser.booleanValue();
                 } else if (IGNORE_UNMAPPED_FIELD.match(currentFieldName)) {

+ 1 - 1
modules/parent-join/src/main/java/org/elasticsearch/join/query/ParentIdQueryBuilder.java

@@ -53,7 +53,7 @@ public final class ParentIdQueryBuilder extends AbstractQueryBuilder<ParentIdQue
     public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
 
     private static final ParseField ID_FIELD = new ParseField("id");
-    private static final ParseField TYPE_FIELD = new ParseField("type", "child_type");
+    private static final ParseField TYPE_FIELD = new ParseField("type");
     private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");
 
     private final String type;

+ 0 - 17
modules/parent-join/src/test/java/org/elasticsearch/join/query/HasParentQueryBuilderTests.java

@@ -23,13 +23,10 @@ import org.apache.lucene.search.MatchNoDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.join.ScoreMode;
 import org.elasticsearch.Version;
-import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.elasticsearch.common.compress.CompressedXContent;
 import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.index.mapper.MapperService;
 import org.elasticsearch.index.query.IdsQueryBuilder;
 import org.elasticsearch.index.query.InnerHitBuilder;
@@ -198,20 +195,6 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ
         assertThat(qse.getMessage(), equalTo("[has_parent] join field [join_field] doesn't hold [just_a_type] as a parent"));
     }
 
-    public void testDeprecatedXContent() throws IOException {
-        XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
-        builder.startObject();
-        builder.startObject("has_parent");
-        builder.field("query");
-        new TermQueryBuilder("a", "a").toXContent(builder, ToXContent.EMPTY_PARAMS);
-        builder.field("type", "foo"); // deprecated
-        builder.endObject();
-        builder.endObject();
-        HasParentQueryBuilder queryBuilder = (HasParentQueryBuilder) parseQuery(builder.string());
-        assertEquals("foo", queryBuilder.type());
-        assertWarnings("Deprecated field [type] used, expected [parent_type] instead");
-    }
-
     public void testToQueryInnerQueryType() throws IOException {
         String[] searchTypes = new String[]{TYPE};
         QueryShardContext shardContext = createShardContext();

+ 0 - 17
modules/parent-join/src/test/java/org/elasticsearch/join/query/LegacyHasParentQueryBuilderTests.java

@@ -26,9 +26,6 @@ import org.elasticsearch.Version;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
 import org.elasticsearch.common.compress.CompressedXContent;
 import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.xcontent.ToXContent;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.index.mapper.MapperService;
 import org.elasticsearch.index.query.IdsQueryBuilder;
 import org.elasticsearch.index.query.InnerHitBuilder;
@@ -186,20 +183,6 @@ public class LegacyHasParentQueryBuilderTests extends AbstractQueryTestCase<HasP
         assertThat(qse.getMessage(), equalTo("[has_parent] no child types found for type [just_a_type]"));
     }
 
-    public void testDeprecatedXContent() throws IOException {
-        XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
-        builder.startObject();
-        builder.startObject("has_parent");
-        builder.field("query");
-        new TermQueryBuilder("a", "a").toXContent(builder, ToXContent.EMPTY_PARAMS);
-        builder.field("type", "foo"); // deprecated
-        builder.endObject();
-        builder.endObject();
-        HasParentQueryBuilder queryBuilder = (HasParentQueryBuilder) parseQuery(builder.string());
-        assertEquals("foo", queryBuilder.type());
-        assertWarnings("Deprecated field [type] used, expected [parent_type] instead");
-    }
-
     public void testToQueryInnerQueryType() throws IOException {
         String[] searchTypes = new String[]{CHILD_TYPE};
         QueryShardContext shardContext = createShardContext();

+ 1 - 1
qa/query-builder-bwc/src/test/java/org/elasticsearch/bwc/QueryBuilderBWCIT.java

@@ -101,7 +101,7 @@ public class QueryBuilderBWCIT extends ESRestTestCase {
                 .tieBreaker(0.01f)
         );
         addCandidate(
-            "\"constant_score\": {\"query\": {\"match_all\": {}}, \"boost\": 0.1}",
+            "\"constant_score\": {\"filter\": {\"match_all\": {}}, \"boost\": 0.1}",
             new ConstantScoreQueryBuilder(new MatchAllQueryBuilder()).boost(0.1f)
         );
         addCandidate(