Skip to content

Commit bfb6512

Browse files
authored
Added no-op support for project_routing query param to REST endpoints that will support cross-project search (#134741)
* Added no-op support for project_routing query param to the REST endpoints for: _msearch _field_caps _search/template _msearch/template _resolve/index _eql/search _sql _mvt (Vector tile search) <index>/_pit (Open PointInTime) <index>/_count _cat/count/{index}
1 parent a29392c commit bfb6512

File tree

30 files changed

+171
-17
lines changed

30 files changed

+171
-17
lines changed

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public List<RestHandler> getRestHandlers(
6767
Predicate<NodeFeature> clusterSupportsFeature
6868
) {
6969
return Arrays.asList(
70-
new RestSearchTemplateAction(clusterSupportsFeature),
70+
new RestSearchTemplateAction(clusterSupportsFeature, settings),
7171
new RestMultiSearchTemplateAction(settings),
7272
new RestRenderSearchTemplateAction()
7373
);

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler {
3434
private static final Set<String> RESPONSE_PARAMS = Set.of(RestSearchAction.TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HITS_AS_INT_PARAM);
3535

3636
private final boolean allowExplicitIndex;
37+
private final Settings settings;
3738

3839
public RestMultiSearchTemplateAction(Settings settings) {
3940
this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings);
41+
this.settings = settings;
4042
}
4143

4244
@Override
@@ -63,7 +65,12 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
6365
/**
6466
* Parses a {@link RestRequest} body and returns a {@link MultiSearchTemplateRequest}
6567
*/
66-
public static MultiSearchTemplateRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
68+
public MultiSearchTemplateRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
69+
if (settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false)) {
70+
// accept but drop project_routing param until fully supported
71+
restRequest.param("project_routing");
72+
}
73+
6774
MultiSearchTemplateRequest multiRequest = new MultiSearchTemplateRequest();
6875
if (restRequest.hasParam("max_concurrent_searches")) {
6976
multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.action.search.SearchRequest;
1313
import org.elasticsearch.client.internal.node.NodeClient;
14+
import org.elasticsearch.common.settings.Settings;
1415
import org.elasticsearch.features.NodeFeature;
1516
import org.elasticsearch.rest.BaseRestHandler;
1617
import org.elasticsearch.rest.RestRequest;
@@ -36,9 +37,11 @@ public class RestSearchTemplateAction extends BaseRestHandler {
3637
private static final Set<String> RESPONSE_PARAMS = Set.of(TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HITS_AS_INT_PARAM);
3738

3839
private final Predicate<NodeFeature> clusterSupportsFeature;
40+
private final Settings settings;
3941

40-
public RestSearchTemplateAction(Predicate<NodeFeature> clusterSupportsFeature) {
42+
public RestSearchTemplateAction(Predicate<NodeFeature> clusterSupportsFeature, Settings settings) {
4143
this.clusterSupportsFeature = clusterSupportsFeature;
44+
this.settings = settings;
4245
}
4346

4447
@Override
@@ -58,6 +61,11 @@ public String getName() {
5861

5962
@Override
6063
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
64+
if (settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false)) {
65+
// accept but drop project_routing param until fully supported
66+
request.param("project_routing");
67+
}
68+
6169
// Creates the search request with all required params
6270
SearchRequest searchRequest = new SearchRequest();
6371
RestSearchAction.parseSearchRequest(

modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.action.search.SearchRequest;
1313
import org.elasticsearch.common.bytes.BytesArray;
14+
import org.elasticsearch.common.settings.Settings;
1415
import org.elasticsearch.rest.RestRequest;
1516
import org.elasticsearch.script.ScriptType;
1617
import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -35,7 +36,7 @@ public void testParseRequest() throws Exception {
3536
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray(data), XContentType.JSON)
3637
.build();
3738

38-
MultiSearchTemplateRequest request = RestMultiSearchTemplateAction.parseRequest(restRequest, true);
39+
MultiSearchTemplateRequest request = new RestMultiSearchTemplateAction(Settings.EMPTY).parseRequest(restRequest, true);
3940

4041
assertThat(request.requests().size(), equalTo(3));
4142
assertThat(request.requests().get(0).getRequest().indices()[0], equalTo("test0"));
@@ -73,7 +74,7 @@ public void testParseWithCarriageReturn() throws Exception {
7374
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray(content), XContentType.JSON)
7475
.build();
7576

76-
MultiSearchTemplateRequest request = RestMultiSearchTemplateAction.parseRequest(restRequest, true);
77+
MultiSearchTemplateRequest request = new RestMultiSearchTemplateAction(Settings.EMPTY).parseRequest(restRequest, true);
7778

7879
assertThat(request.requests().size(), equalTo(1));
7980
assertThat(request.requests().get(0).getRequest().indices()[0], equalTo("test0"));
@@ -125,7 +126,7 @@ public void testMultiSearchTemplateToJson() throws Exception {
125126
// Deserialize the request
126127
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray(serialized), XContentType.JSON)
127128
.build();
128-
MultiSearchTemplateRequest deser = RestMultiSearchTemplateAction.parseRequest(restRequest, true);
129+
MultiSearchTemplateRequest deser = new RestMultiSearchTemplateAction(Settings.EMPTY).parseRequest(restRequest, true);
129130

130131
// For object equality purposes need to set the search requests' source to non-null
131132
for (SearchTemplateRequest str : deser.requests()) {

rest-api-spec/src/main/resources/rest-api-spec/api/cat.count.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
"description": "Return help information",
5050
"default": false
5151
},
52+
"project_routing": {
53+
"type": "string",
54+
"description": "A Lucene query using project metadata tags to limit which projects to search, such as _alias:_origin or _alias:*pr*. Only supported in serverless."
55+
},
5256
"s": {
5357
"type": "list",
5458
"description": "Comma-separated list of column names or column aliases to sort by"

rest-api-spec/src/main/resources/rest-api-spec/api/count.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
"type": "string",
7272
"description": "Specify the node or shard the operation should be performed on (default: random)"
7373
},
74+
"project_routing": {
75+
"type": "string",
76+
"description": "A Lucene query using project metadata tags to limit which projects to search, such as _alias:_origin or _alias:*pr*. Only supported in serverless."
77+
},
7478
"routing": {
7579
"type": "list",
7680
"description": "A comma-separated list of specific routing values"

rest-api-spec/src/main/resources/rest-api-spec/api/eql.search.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
],
8181
"default": "open",
8282
"description": "Whether to expand wildcard expression to concrete indices that are open, closed or both."
83+
},
84+
"project_routing": {
85+
"type": "string",
86+
"description": "A Lucene query using project metadata tags to limit which projects to search, such as _alias:_origin or _alias:*pr*. Only supported in serverless."
8387
}
8488
},
8589
"body": {

rest-api-spec/src/main/resources/rest-api-spec/api/field_caps.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
"type": "boolean",
8181
"default": true,
8282
"description": "Include empty fields in result"
83+
},
84+
"project_routing": {
85+
"type": "string",
86+
"description": "A Lucene query using project metadata tags to limit which projects to search, such as _alias:_origin or _alias:*pr*. Only supported in serverless."
8387
}
8488
},
8589
"body": {

rest-api-spec/src/main/resources/rest-api-spec/api/indices.resolve_index.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
],
6161
"default": "",
6262
"description": "Filter indices by index mode. Comma-separated list of IndexMode. Empty means no filter."
63+
},
64+
"project_routing": {
65+
"type": "string",
66+
"description": "A Lucene query using project metadata tags to limit which projects to search, such as _alias:_origin or _alias:*pr*. Only supported in serverless."
6367
}
6468
}
6569
}

rest-api-spec/src/main/resources/rest-api-spec/api/msearch.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@
103103
"default": "open",
104104
"description": "Whether to expand wildcard expression to concrete indices that are open, closed or both."
105105
},
106+
"project_routing": {
107+
"type": "string",
108+
"description": "A Lucene query using project metadata tags to limit which projects to search, such as _alias:_origin or _alias:*pr*. Only supported in serverless."
109+
},
106110
"routing": {
107111
"type": "list",
108112
"description": "A comma-separated list of specific routing values"

0 commit comments

Comments
 (0)