Browse Source

Deprecate legacy params from range query (#113286) (#113610)

Deprecate to, from, include_lower, include_upper range query params.
These params have been removed from our documentation in v. 0.90.4 (d6ecdecc19d54b4a37b033a2237a4c76601e9a2d),
but did not got through deprecation cycle.

These params to be removed in v9.0.

Related to #81276

Closes #48538
Mayya Sharipova 1 year ago
parent
commit
7719f17457

+ 10 - 0
docs/changelog/113286.yaml

@@ -0,0 +1,10 @@
+pr: 113286
+summary: Deprecate legacy params from range query
+area: Search
+type: deprecation
+issues: []
+deprecation:
+  title: Deprecate legacy params from range query
+  area: REST API
+  details: Range query will not longer accept `to`, `from`, `include_lower`, and `include_upper` parameters.
+  impact: Instead use `gt`, `gte`, `lt` and `lte` parameters.

+ 2 - 2
docs/reference/aggregations/bucket/histogram-aggregation.asciidoc

@@ -165,7 +165,7 @@ Example:
 POST /sales/_search?size=0
 POST /sales/_search?size=0
 {
 {
   "query": {
   "query": {
-    "constant_score": { "filter": { "range": { "price": { "to": "500" } } } }
+    "constant_score": { "filter": { "range": { "price": { "lte": "500" } } } }
   },
   },
   "aggs": {
   "aggs": {
     "prices": {
     "prices": {
@@ -202,7 +202,7 @@ Example:
 POST /sales/_search?size=0
 POST /sales/_search?size=0
 {
 {
   "query": {
   "query": {
-    "constant_score": { "filter": { "range": { "price": { "to": "500" } } } }
+    "constant_score": { "filter": { "range": { "price": { "lte": "500" } } } }
   },
   },
   "aggs": {
   "aggs": {
     "prices": {
     "prices": {

+ 1 - 1
docs/reference/watcher/getting-started.asciidoc

@@ -135,7 +135,7 @@ GET .watcher-history*/_search?pretty
     "bool" : {
     "bool" : {
       "must" : [
       "must" : [
         { "match" : { "result.condition.met" : true }},
         { "match" : { "result.condition.met" : true }},
-        { "range" : { "result.execution_time" : { "from" : "now-10s" }}}
+        { "range" : { "result.execution_time" : { "gte" : "now-10s" }}}
       ]
       ]
     }
     }
   }
   }

+ 4 - 4
docs/reference/watcher/transform/search.asciidoc

@@ -119,8 +119,8 @@ time of the watch:
                 {
                 {
                   "range" : {
                   "range" : {
                     "@timestamp" : {
                     "@timestamp" : {
-                      "from" : "{{ctx.trigger.scheduled_time}}||-30s",
-                      "to" : "{{ctx.trigger.triggered_time}}"
+                      "gte" : "{{ctx.trigger.scheduled_time}}||-30s",
+                      "lte" : "{{ctx.trigger.triggered_time}}"
                     }
                     }
                   }
                   }
                 }
                 }
@@ -159,8 +159,8 @@ The following is an example of using templates that refer to provided parameters
                   {
                   {
                     "range" : {
                     "range" : {
                       "@timestamp" : {
                       "@timestamp" : {
-                        "from" : "{{ctx.trigger.scheduled_time}}||-30s",
-                        "to" : "{{ctx.trigger.triggered_time}}"
+                        "gte" : "{{ctx.trigger.scheduled_time}}||-30s",
+                        "lte" : "{{ctx.trigger.triggered_time}}"
                       }
                       }
                     }
                     }
                   }
                   }

+ 4 - 0
modules/rank-eval/build.gradle

@@ -25,3 +25,7 @@ testClusters.configureEach {
   // Modules who's integration is explicitly tested in integration tests
   // Modules who's integration is explicitly tested in integration tests
   module ':modules:lang-mustache'
   module ':modules:lang-mustache'
 }
 }
+
+tasks.named("yamlRestTestV7CompatTransform").configure({ task ->
+  task.skipTest("rank_eval/30_failures/Response format", "warning does not exist for compatibility")
+})

+ 1 - 1
modules/rank-eval/src/yamlRestTest/resources/rest-api-spec/test/rank_eval/30_failures.yml

@@ -21,7 +21,7 @@
             },
             },
             {
             {
                 "id" : "invalid_query",
                 "id" : "invalid_query",
-                "request": { "query": { "range" : { "bar" : { "from" : "Basel", "time_zone": "+01:00" }}}},
+                "request": { "query": { "range" : { "bar" : { "gte" : "Basel", "time_zone": "+01:00" }}}},
                 "ratings": [{"_index": "foo", "_id": "doc1", "rating": 1}]
                 "ratings": [{"_index": "foo", "_id": "doc1", "rating": 1}]
             }
             }
           ],
           ],

+ 1 - 0
modules/runtime-fields-common/build.gradle

@@ -28,4 +28,5 @@ tasks.named("yamlRestTestV7CompatTransform").configure { task ->
   task.skipTest("runtime_fields/101_geo_point_from_source/fetch fields from source", "Format changed. Old format was a bug.")
   task.skipTest("runtime_fields/101_geo_point_from_source/fetch fields from source", "Format changed. Old format was a bug.")
   task.skipTest("runtime_fields/102_geo_point_source_in_query/fetch fields from source", "Format changed. Old format was a bug.")
   task.skipTest("runtime_fields/102_geo_point_source_in_query/fetch fields from source", "Format changed. Old format was a bug.")
   task.skipTest("runtime_fields/103_geo_point_calculated_at_index/fetch fields from source", "Format changed. Old format was a bug.")
   task.skipTest("runtime_fields/103_geo_point_calculated_at_index/fetch fields from source", "Format changed. Old format was a bug.")
+  task.skipTestsByFilePattern("**/runtime_fields/110_composite.yml", "warning does not exist for compatibility")
 }
 }

+ 2 - 2
modules/runtime-fields-common/src/yamlRestTest/resources/rest-api-spec/test/runtime_fields/110_composite.yml

@@ -83,8 +83,8 @@ query:
           query:
           query:
             range:
             range:
               http.clientip:
               http.clientip:
-                from: 232.0.0.0
-                to: 253.0.0.0
+                gte: 232.0.0.0
+                lte: 253.0.0.0
   - match: { hits.total.value: 4 }
   - match: { hits.total.value: 4 }
 
 
 ---
 ---

+ 4 - 0
rest-api-spec/build.gradle

@@ -244,3 +244,7 @@ tasks.named("precommit").configure {
   dependsOn 'enforceYamlTestConvention'
   dependsOn 'enforceYamlTestConvention'
 }
 }
 
 
+tasks.named("yamlRestTestV7CompatTransform").configure({ task ->
+  task.skipTest("indices.sort/10_basic/Index Sort", "warning does not exist for compatibility")
+  task.skipTest("search/330_fetch_fields/Test search rewrite", "warning does not exist for compatibility")
+})

+ 3 - 3
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.sort/10_basic.yml

@@ -101,7 +101,7 @@
         index: test
         index: test
         body:
         body:
           sort: ["rank"]
           sort: ["rank"]
-          query: {"range": { "rank": { "from": 0 } } }
+          query: {"range": { "rank": { "gte": 0 } } }
           track_total_hits: false
           track_total_hits: false
           size: 1
           size: 1
 
 
@@ -142,7 +142,7 @@
         index: test
         index: test
         body:
         body:
           sort: ["rank"]
           sort: ["rank"]
-          query: {"range": { "rank": { "from": 0 } } }
+          query: {"range": { "rank": { "gte": 0 } } }
           track_total_hits: false
           track_total_hits: false
           size: 3
           size: 3
 
 
@@ -160,6 +160,6 @@
         scroll: 1m
         scroll: 1m
         body:
         body:
           sort: ["rank"]
           sort: ["rank"]
-          query: {"range": { "rank": { "from": 0 } } }
+          query: {"range": { "rank": { "gte": 0 } } }
           track_total_hits: false
           track_total_hits: false
           size: 3
           size: 3

+ 1 - 1
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search/330_fetch_fields.yml

@@ -252,7 +252,7 @@
           query:
           query:
             range:
             range:
               date:
               date:
-                from: "1990-12-29T22:30:00.000Z"
+                gte: "1990-12-29T22:30:00.000Z"
           fields:
           fields:
             - field: date
             - field: date
               format: "yyyy/MM/dd"
               format: "yyyy/MM/dd"

+ 26 - 0
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search/500_date_range.yml

@@ -123,3 +123,29 @@ setup:
   - match: { hits.total: 1 }
   - match: { hits.total: 1 }
   - length: { hits.hits: 1 }
   - length: { hits.hits: 1 }
   - match: { hits.hits.0._id: "4" }
   - match: { hits.hits.0._id: "4" }
+
+
+---
+"from, to, include_lower, include_upper deprecated":
+  - requires:
+      cluster_features: "gte_v8.16.0"
+      reason: 'from, to, include_lower, include_upper parameters are deprecated since 8.16.0'
+      test_runner_features: warnings
+
+  - do:
+      warnings:
+        - "Deprecated field [from] used, this field is unused and will be removed entirely"
+        - "Deprecated field [to] used, this field is unused and will be removed entirely"
+        - "Deprecated field [include_lower] used, this field is unused and will be removed entirely"
+        - "Deprecated field [include_upper] used, this field is unused and will be removed entirely"
+      search:
+        index: dates
+        body:
+          sort: field
+          query:
+            range:
+              date:
+                from: 1000
+                to: 2023
+                include_lower: false
+                include_upper: false

+ 4 - 4
server/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java

@@ -45,10 +45,10 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
 
 
     public static final ParseField LTE_FIELD = new ParseField("lte");
     public static final ParseField LTE_FIELD = new ParseField("lte");
     public static final ParseField GTE_FIELD = new ParseField("gte");
     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");
-    private static final ParseField INCLUDE_UPPER_FIELD = new ParseField("include_upper");
+    public static final ParseField FROM_FIELD = new ParseField("from").withAllDeprecated();
+    public static final ParseField TO_FIELD = new ParseField("to").withAllDeprecated();
+    private static final ParseField INCLUDE_LOWER_FIELD = new ParseField("include_lower").withAllDeprecated();
+    private static final ParseField INCLUDE_UPPER_FIELD = new ParseField("include_upper").withAllDeprecated();
     public static final ParseField GT_FIELD = new ParseField("gt");
     public static final ParseField GT_FIELD = new ParseField("gt");
     public static final ParseField LT_FIELD = new ParseField("lt");
     public static final ParseField LT_FIELD = new ParseField("lt");
     private static final ParseField TIME_ZONE_FIELD = new ParseField("time_zone");
     private static final ParseField TIME_ZONE_FIELD = new ParseField("time_zone");

+ 2 - 42
server/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java

@@ -35,8 +35,6 @@ import java.io.IOException;
 import java.time.Instant;
 import java.time.Instant;
 import java.time.ZoneOffset;
 import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.time.ZonedDateTime;
-import java.util.HashMap;
-import java.util.Map;
 
 
 import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
 import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.equalTo;
@@ -111,44 +109,6 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
         return query;
         return query;
     }
     }
 
 
-    @Override
-    protected Map<String, RangeQueryBuilder> getAlternateVersions() {
-        Map<String, RangeQueryBuilder> alternateVersions = new HashMap<>();
-        RangeQueryBuilder rangeQueryBuilder = new RangeQueryBuilder(INT_FIELD_NAME);
-
-        rangeQueryBuilder.includeLower(randomBoolean());
-        rangeQueryBuilder.includeUpper(randomBoolean());
-
-        if (randomBoolean()) {
-            rangeQueryBuilder.from(randomIntBetween(1, 100));
-        }
-
-        if (randomBoolean()) {
-            rangeQueryBuilder.to(randomIntBetween(101, 200));
-        }
-
-        String query = Strings.format(
-            """
-                {
-                    "range":{
-                        "%s": {
-                            "include_lower":%s,
-                            "include_upper":%s,
-                            "from":%s,
-                            "to":%s
-                        }
-                    }
-                }""",
-            INT_FIELD_NAME,
-            rangeQueryBuilder.includeLower(),
-            rangeQueryBuilder.includeUpper(),
-            rangeQueryBuilder.from(),
-            rangeQueryBuilder.to()
-        );
-        alternateVersions.put(query, rangeQueryBuilder);
-        return alternateVersions;
-    }
-
     @Override
     @Override
     protected void doAssertLuceneQuery(RangeQueryBuilder queryBuilder, Query query, SearchExecutionContext context) throws IOException {
     protected void doAssertLuceneQuery(RangeQueryBuilder queryBuilder, Query query, SearchExecutionContext context) throws IOException {
         String expectedFieldName = expectedFieldName(queryBuilder.fieldName());
         String expectedFieldName = expectedFieldName(queryBuilder.fieldName());
@@ -420,8 +380,8 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
             {
             {
               "range" : {
               "range" : {
                 "timestamp" : {
                 "timestamp" : {
-                  "from" : "2015-01-01 00:00:00",
-                  "to" : "now",
+                  "gte" : "2015-01-01 00:00:00",
+                  "lte" : "now",
                   "boost" : 1.0,
                   "boost" : 1.0,
                   "_name" : "my_range"
                   "_name" : "my_range"
                 }
                 }

+ 4 - 0
x-pack/plugin/build.gradle

@@ -199,3 +199,7 @@ tasks.named("precommit").configure {
   dependsOn 'enforceYamlTestConvention', 'enforceApiSpecsConvention'
   dependsOn 'enforceYamlTestConvention', 'enforceApiSpecsConvention'
 }
 }
 
 
+tasks.named("yamlRestTestV7CompatTransform").configure({ task ->
+  task.skipTest("security/10_forbidden/Test bulk response with invalid credentials", "warning does not exist for compatibility")
+})
+