Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate legacy params from range query #113286

Merged
merged 15 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/changelog/113286.yaml
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Example:
POST /sales/_search?size=0
{
"query": {
"constant_score": { "filter": { "range": { "price": { "to": "500" } } } }
"constant_score": { "filter": { "range": { "price": { "lte": "500" } } } }
},
"aggs": {
"prices": {
Expand Down Expand Up @@ -202,7 +202,7 @@ Example:
POST /sales/_search?size=0
{
"query": {
"constant_score": { "filter": { "range": { "price": { "to": "500" } } } }
"constant_score": { "filter": { "range": { "price": { "lte": "500" } } } }
},
"aggs": {
"prices": {
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/watcher/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ GET .watcher-history*/_search?pretty
"bool" : {
"must" : [
{ "match" : { "result.condition.met" : true }},
{ "range" : { "result.execution_time" : { "from" : "now-10s" }}}
{ "range" : { "result.execution_time" : { "gte" : "now-10s" }}}
]
}
}
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/watcher/transform/search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ time of the watch:
{
"range" : {
"@timestamp" : {
"from" : "{{ctx.trigger.scheduled_time}}||-30s",
"to" : "{{ctx.trigger.triggered_time}}"
"gte" : "{{ctx.trigger.scheduled_time}}||-30s",
"lte" : "{{ctx.trigger.triggered_time}}"
}
}
}
Expand Down Expand Up @@ -159,8 +159,8 @@ The following is an example of using templates that refer to provided parameters
{
"range" : {
"@timestamp" : {
"from" : "{{ctx.trigger.scheduled_time}}||-30s",
"to" : "{{ctx.trigger.triggered_time}}"
"gte" : "{{ctx.trigger.scheduled_time}}||-30s",
"lte" : "{{ctx.trigger.triggered_time}}"
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions modules/rank-eval/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ testClusters.configureEach {
// Modules who's integration is explicitly tested in integration tests
module ':modules:lang-mustache'
}

tasks.named("yamlRestCompatTestTransform").configure({ task ->
task.skipTest("rank_eval/30_failures/Response format", "warning does not exist for compatibility")
})
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
{
"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}]
}
],
Expand Down
4 changes: 4 additions & 0 deletions modules/runtime-fields-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ dependencies {
api project(':libs:elasticsearch-grok')
api project(':libs:elasticsearch-dissect')
}

tasks.named("yamlRestCompatTestTransform").configure({ task ->
task.skipTestsByFilePattern("**/runtime_fields/110_composite.yml", "warning does not exist for compatibility")
})
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ query:
query:
range:
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 }

---
Expand Down
3 changes: 3 additions & 0 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ tests:
- class: org.elasticsearch.xpack.ml.integration.MlJobIT
method: testDeleteJob_TimingStatsDocumentIsDeleted
issue: https://github.com/elastic/elasticsearch/issues/113370
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
method: test {p0=search/500_date_range/from, to, include_lower, include_upper deprecated}
issue: https://github.com/elastic/elasticsearch/pull/113286
- class: org.elasticsearch.xpack.esql.EsqlAsyncSecurityIT
method: testLimitedPrivilege
issue: https://github.com/elastic/elasticsearch/issues/113419
Expand Down
2 changes: 2 additions & 0 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ tasks.named("precommit").configure {

tasks.named("yamlRestCompatTestTransform").configure({ task ->
task.skipTest("tsdb/140_routing_path/multi-value routing path field", "Multi-value routing paths are allowed now. See #112645")
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")
})
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
index: test
body:
sort: ["rank"]
query: {"range": { "rank": { "from": 0 } } }
query: {"range": { "rank": { "gte": 0 } } }
track_total_hits: false
size: 1

Expand Down Expand Up @@ -142,7 +142,7 @@
index: test
body:
sort: ["rank"]
query: {"range": { "rank": { "from": 0 } } }
query: {"range": { "rank": { "gte": 0 } } }
track_total_hits: false
size: 3

Expand All @@ -160,6 +160,6 @@
scroll: 1m
body:
sort: ["rank"]
query: {"range": { "rank": { "from": 0 } } }
query: {"range": { "rank": { "gte": 0 } } }
track_total_hits: false
size: 3
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
query:
range:
date:
from: "1990-12-29T22:30:00.000Z"
gte: "1990-12-29T22:30:00.000Z"
fields:
- field: date
format: "yyyy/MM/dd"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,29 @@ setup:
- match: { hits.total: 1 }
- length: { hits.hits: 1 }
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i

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");
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 LT_FIELD = new ParseField("lt");
private static final ParseField TIME_ZONE_FIELD = new ParseField("time_zone");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;

import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -111,44 +109,6 @@ protected RangeQueryBuilder doCreateTestQueryBuilder() {
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
protected void doAssertLuceneQuery(RangeQueryBuilder queryBuilder, Query query, SearchExecutionContext context) throws IOException {
String expectedFieldName = expectedFieldName(queryBuilder.fieldName());
Expand Down Expand Up @@ -420,8 +380,8 @@ public void testNamedQueryParsing() throws IOException {
{
"range" : {
"timestamp" : {
"from" : "2015-01-01 00:00:00",
"to" : "now",
"gte" : "2015-01-01 00:00:00",
"lte" : "now",
"boost" : 1.0,
"_name" : "my_range"
}
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ tasks.named("precommit").configure {
dependsOn 'enforceYamlTestConvention', 'enforceApiSpecsConvention'
}

tasks.named("yamlRestCompatTestTransform").configure({ task ->
task.skipTest("security/10_forbidden/Test bulk response with invalid credentials", "warning does not exist for compatibility")
})