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 (#113128)

This commit adds a capability and transport version for new regex and range interval query support.
  • Loading branch information
ChrisHegarty authored Sep 19, 2024
1 parent d1fbaab commit 9eec2c4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 8 deletions.
2 changes: 1 addition & 1 deletion qa/ccs-common-rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: 'elasticsearch.internal-yaml-rest-test'

restResources {
restApi {
include '_common', 'bulk', 'count', 'cluster', 'field_caps', 'get', 'knn_search', 'index', 'indices', 'msearch',
include 'capabilities', '_common', 'bulk', 'count', 'cluster', 'field_caps', 'get', 'knn_search', 'index', 'indices', 'msearch',
'search', 'async_search', 'graph', '*_point_in_time', 'info', 'scroll', 'clear_scroll', 'search_mvt', 'eql', 'sql'
}
restTests {
Expand Down
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"
capabilities:
- method: POST
path: /_search
capabilities: [ range_regexp_interval_queries ]
test_runner_features: capabilities
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"
capabilities:
- method: POST
path: /_search
capabilities: [ range_regexp_interval_queries ]
test_runner_features: capabilities
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 @@ -219,6 +219,7 @@ static TransportVersion def(int id) {
public static final TransportVersion SIMULATE_COMPONENT_TEMPLATES_SUBSTITUTIONS = def(8_743_00_0);
public static final TransportVersion ML_INFERENCE_IBM_WATSONX_EMBEDDINGS_ADDED = def(8_744_00_0);
public static final TransportVersion BULK_INCREMENTAL_STATE = def(8_745_00_0);
public static final TransportVersion REGEX_AND_RANGE_INTERVAL_QUERIES = def(8_746_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import org.apache.lucene.queries.intervals.Intervals;
import org.apache.lucene.queries.intervals.IntervalsSource;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.TransportVersions;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.NamedWriteable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.VersionedNamedWriteable;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.analysis.NamedAnalyzer;
Expand Down Expand Up @@ -753,7 +755,7 @@ String getUseField() {
}
}

public static class Regexp extends IntervalsSourceProvider {
public static class Regexp extends IntervalsSourceProvider implements VersionedNamedWriteable {

public static final String NAME = "regexp";

Expand Down Expand Up @@ -821,6 +823,11 @@ public String getWriteableName() {
return NAME;
}

@Override
public TransportVersion getMinimalSupportedVersion() {
return TransportVersions.REGEX_AND_RANGE_INTERVAL_QUERIES;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(pattern);
Expand Down Expand Up @@ -1032,7 +1039,7 @@ String getUseField() {
}
}

public static class Range extends IntervalsSourceProvider {
public static class Range extends IntervalsSourceProvider implements VersionedNamedWriteable {

public static final String NAME = "range";

Expand Down Expand Up @@ -1120,6 +1127,11 @@ public String getWriteableName() {
return NAME;
}

@Override
public TransportVersion getMinimalSupportedVersion() {
return TransportVersions.REGEX_AND_RANGE_INTERVAL_QUERIES;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(lowerTerm);
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);
}
2 changes: 1 addition & 1 deletion x-pack/qa/runtime-fields/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ subprojects {

restResources {
restApi {
include '_common', 'bulk', 'count', 'cluster', 'index', 'indices', 'field_caps', 'msearch',
include 'capabilities', '_common', 'bulk', 'count', 'cluster', 'index', 'indices', 'field_caps', 'msearch',
'search', 'async_search', 'graph', '*_point_in_time', 'put_script', 'scripts_painless_execute'
}
restTests {
Expand Down

0 comments on commit 9eec2c4

Please sign in to comment.