Skip to content

Commit

Permalink
Add a capability and transport version for new regex and range interv…
Browse files Browse the repository at this point in the history
…al query support
  • Loading branch information
elasticsearchmachine committed Sep 18, 2024
1 parent ff74c90 commit c70e967
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public List<Route> routes() {
);
}

@Override
public Set<String> supportedCapabilities() {
return SearchCapabilities.CAPABILITIES;
}

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> CAPABILITIES = Set.of(RANGE_REGEX_INTERVAL_QUERY_CAPABILITY);
}

0 comments on commit c70e967

Please sign in to comment.