Skip to content

Commit 9eec2c4

Browse files
authored
Add a capability and transport version for new regex and range interval query support (#113128)
This commit adds a capability and transport version for new regex and range interval query support.
1 parent d1fbaab commit 9eec2c4

File tree

7 files changed

+59
-8
lines changed

7 files changed

+59
-8
lines changed

qa/ccs-common-rest/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ apply plugin: 'elasticsearch.internal-yaml-rest-test'
1010

1111
restResources {
1212
restApi {
13-
include '_common', 'bulk', 'count', 'cluster', 'field_caps', 'get', 'knn_search', 'index', 'indices', 'msearch',
13+
include 'capabilities', '_common', 'bulk', 'count', 'cluster', 'field_caps', 'get', 'knn_search', 'index', 'indices', 'msearch',
1414
'search', 'async_search', 'graph', '*_point_in_time', 'info', 'scroll', 'clear_scroll', 'search_mvt', 'eql', 'sql'
1515
}
1616
restTests {

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search/230_interval_query.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,12 @@ setup:
479479
---
480480
"Test regexp":
481481
- requires:
482-
cluster_features: "gte_v8.16.0"
483-
reason: "Implemented in 8.16"
482+
capabilities:
483+
- method: POST
484+
path: /_search
485+
capabilities: [ range_regexp_interval_queries ]
486+
test_runner_features: capabilities
487+
reason: "Support for range and regexp interval queries capability required"
484488
- do:
485489
search:
486490
index: test
@@ -500,8 +504,12 @@ setup:
500504
---
501505
"Test range":
502506
- requires:
503-
cluster_features: "gte_v8.16.0"
504-
reason: "Implemented in 8.16"
507+
capabilities:
508+
- method: POST
509+
path: /_search
510+
capabilities: [ range_regexp_interval_queries ]
511+
test_runner_features: capabilities
512+
reason: "Support for range and regexp interval queries capability required"
505513
- do:
506514
search:
507515
index: test

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static TransportVersion def(int id) {
219219
public static final TransportVersion SIMULATE_COMPONENT_TEMPLATES_SUBSTITUTIONS = def(8_743_00_0);
220220
public static final TransportVersion ML_INFERENCE_IBM_WATSONX_EMBEDDINGS_ADDED = def(8_744_00_0);
221221
public static final TransportVersion BULK_INCREMENTAL_STATE = def(8_745_00_0);
222+
public static final TransportVersion REGEX_AND_RANGE_INTERVAL_QUERIES = def(8_746_00_0);
222223

223224
/*
224225
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
import org.apache.lucene.queries.intervals.Intervals;
1515
import org.apache.lucene.queries.intervals.IntervalsSource;
1616
import org.apache.lucene.util.BytesRef;
17+
import org.elasticsearch.TransportVersion;
1718
import org.elasticsearch.TransportVersions;
1819
import org.elasticsearch.common.ParsingException;
1920
import org.elasticsearch.common.io.stream.NamedWriteable;
2021
import org.elasticsearch.common.io.stream.StreamInput;
2122
import org.elasticsearch.common.io.stream.StreamOutput;
23+
import org.elasticsearch.common.io.stream.VersionedNamedWriteable;
2224
import org.elasticsearch.common.io.stream.Writeable;
2325
import org.elasticsearch.common.unit.Fuzziness;
2426
import org.elasticsearch.index.analysis.NamedAnalyzer;
@@ -753,7 +755,7 @@ String getUseField() {
753755
}
754756
}
755757

756-
public static class Regexp extends IntervalsSourceProvider {
758+
public static class Regexp extends IntervalsSourceProvider implements VersionedNamedWriteable {
757759

758760
public static final String NAME = "regexp";
759761

@@ -821,6 +823,11 @@ public String getWriteableName() {
821823
return NAME;
822824
}
823825

826+
@Override
827+
public TransportVersion getMinimalSupportedVersion() {
828+
return TransportVersions.REGEX_AND_RANGE_INTERVAL_QUERIES;
829+
}
830+
824831
@Override
825832
public void writeTo(StreamOutput out) throws IOException {
826833
out.writeString(pattern);
@@ -1032,7 +1039,7 @@ String getUseField() {
10321039
}
10331040
}
10341041

1035-
public static class Range extends IntervalsSourceProvider {
1042+
public static class Range extends IntervalsSourceProvider implements VersionedNamedWriteable {
10361043

10371044
public static final String NAME = "range";
10381045

@@ -1120,6 +1127,11 @@ public String getWriteableName() {
11201127
return NAME;
11211128
}
11221129

1130+
@Override
1131+
public TransportVersion getMinimalSupportedVersion() {
1132+
return TransportVersions.REGEX_AND_RANGE_INTERVAL_QUERIES;
1133+
}
1134+
11231135
@Override
11241136
public void writeTo(StreamOutput out) throws IOException {
11251137
out.writeString(lowerTerm);

server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public List<Route> routes() {
9595
);
9696
}
9797

98+
@Override
99+
public Set<String> supportedCapabilities() {
100+
return SearchCapabilities.CAPABILITIES;
101+
}
102+
98103
@Override
99104
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
100105

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.rest.action.search;
11+
12+
import java.util.Set;
13+
14+
/**
15+
* A {@link Set} of "capabilities" supported by the {@link RestSearchAction}.
16+
*/
17+
public final class SearchCapabilities {
18+
19+
private SearchCapabilities() {}
20+
21+
/** Support regex and range match rules in interval queries. */
22+
private static final String RANGE_REGEX_INTERVAL_QUERY_CAPABILITY = "range_regexp_interval_queries";
23+
24+
public static final Set<String> CAPABILITIES = Set.of(RANGE_REGEX_INTERVAL_QUERY_CAPABILITY);
25+
}

x-pack/qa/runtime-fields/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ subprojects {
2929

3030
restResources {
3131
restApi {
32-
include '_common', 'bulk', 'count', 'cluster', 'index', 'indices', 'field_caps', 'msearch',
32+
include 'capabilities', '_common', 'bulk', 'count', 'cluster', 'index', 'indices', 'field_caps', 'msearch',
3333
'search', 'async_search', 'graph', '*_point_in_time', 'put_script', 'scripts_painless_execute'
3434
}
3535
restTests {

0 commit comments

Comments
 (0)