diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search/230_interval_query.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search/230_interval_query.yml index e828c9ce8d8a8..32ea6b89000fc 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search/230_interval_query.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search/230_interval_query.yml @@ -479,8 +479,12 @@ setup: --- "Test regexp": - requires: - cluster_features: "gte_v8.16.0" - reason: "Implemented in 8.16" + test_runner_features: [ capabilities ] + capabilities: + - method: POST + path: /_search + capabilities: [ range_regexp_interval_queries ] + reason: "Support for range and regexp interval queries capability required" - do: search: index: test @@ -500,8 +504,12 @@ setup: --- "Test range": - requires: - cluster_features: "gte_v8.16.0" - reason: "Implemented in 8.16" + test_runner_features: [ capabilities ] + capabilities: + - method: POST + path: /_search + capabilities: [ range_regexp_interval_queries ] + reason: "Support for range and regexp interval queries capability required" - do: search: index: test diff --git a/server/src/main/java/org/elasticsearch/TransportVersions.java b/server/src/main/java/org/elasticsearch/TransportVersions.java index 20b92b9b64137..e9156e466d751 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersions.java +++ b/server/src/main/java/org/elasticsearch/TransportVersions.java @@ -217,6 +217,7 @@ static TransportVersion def(int id) { public static final TransportVersion ROUTING_TABLE_VERSION_REMOVED = def(8_741_00_0); public static final TransportVersion ML_SCHEDULED_EVENT_TIME_SHIFT_CONFIGURATION = def(8_742_00_0); public static final TransportVersion SIMULATE_COMPONENT_TEMPLATES_SUBSTITUTIONS = def(8_743_00_0); + public static final TransportVersion REGEX_AND_RANGE_INTERVAL_QUERIES = def(8_744_00_0); /* * STOP! READ THIS FIRST! No, really, diff --git a/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java b/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java index 2fcae3c954bf7..8bab49721a9b9 100644 --- a/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java +++ b/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java @@ -823,6 +823,14 @@ public String getWriteableName() { @Override public void writeTo(StreamOutput out) throws IOException { + if (out.getTransportVersion().before(TransportVersions.REGEX_AND_RANGE_INTERVAL_QUERIES)) { + throw new UnsupportedOperationException( + "regex interval requires at least version " + + TransportVersions.REGEX_AND_RANGE_INTERVAL_QUERIES + + " but was " + + out.getTransportVersion() + ); + } out.writeString(pattern); out.writeOptionalString(analyzer); out.writeOptionalString(useField); @@ -1122,6 +1130,14 @@ public String getWriteableName() { @Override public void writeTo(StreamOutput out) throws IOException { + if (out.getTransportVersion().before(TransportVersions.REGEX_AND_RANGE_INTERVAL_QUERIES)) { + throw new UnsupportedOperationException( + "range interval requires at least version " + + TransportVersions.REGEX_AND_RANGE_INTERVAL_QUERIES + + " but was " + + out.getTransportVersion() + ); + } out.writeString(lowerTerm); out.writeString(upperTerm); out.writeBoolean(includeLower); diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 28330c7c45479..38157efd8a370 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -95,6 +95,11 @@ public List routes() { ); } + @Override + public Set supportedCapabilities() { + return SearchCapabilities.CAPABILITIES; + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/SearchCapabilities.java b/server/src/main/java/org/elasticsearch/rest/action/search/SearchCapabilities.java new file mode 100644 index 0000000000000..45fd6afe4fca6 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/rest/action/search/SearchCapabilities.java @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.rest.action.search; + +import java.util.Set; + +/** + * A {@link Set} of "capabilities" supported by the {@link RestSearchAction}. + */ +public final class SearchCapabilities { + + private SearchCapabilities() {} + + /** Support regex and range match rules in interval queries. */ + private static final String RANGE_REGEX_INTERVAL_QUERY_CAPABILITY = "range_regexp_interval_queries"; + + public static final Set CAPABILITIES = Set.of(RANGE_REGEX_INTERVAL_QUERY_CAPABILITY); +}