Skip to content

Commit ac687e0

Browse files
authored
Move query interceptor to an internal plugin interface (#120308)
Query interceptor is meant for internal modules to implement, not any external plugin. Yet it is defined on SearchPlugin that is available to all plugin authors. This commit creates an InternalSearchPlugin interface and moves the query interceptor method to that.
1 parent 4c1c3b8 commit ac687e0

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

server/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@
394394
exports org.elasticsearch.action.downsample;
395395
exports org.elasticsearch.plugins.internal
396396
to
397+
org.elasticsearch.inference,
397398
org.elasticsearch.metering,
398399
org.elasticsearch.stateless,
399400
org.elasticsearch.settings.secure,

server/src/main/java/org/elasticsearch/indices/IndicesServiceBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.elasticsearch.plugins.EnginePlugin;
3535
import org.elasticsearch.plugins.IndexStorePlugin;
3636
import org.elasticsearch.plugins.PluginsService;
37-
import org.elasticsearch.plugins.SearchPlugin;
37+
import org.elasticsearch.plugins.internal.InternalSearchPlugin;
3838
import org.elasticsearch.plugins.internal.rewriter.QueryRewriteInterceptor;
3939
import org.elasticsearch.script.ScriptService;
4040
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
@@ -266,8 +266,8 @@ public IndicesService build() {
266266
.flatMap(m -> m.entrySet().stream())
267267
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
268268

269-
var queryRewriteInterceptors = pluginsService.filterPlugins(SearchPlugin.class)
270-
.map(SearchPlugin::getQueryRewriteInterceptors)
269+
var queryRewriteInterceptors = pluginsService.filterPlugins(InternalSearchPlugin.class)
270+
.map(InternalSearchPlugin::getQueryRewriteInterceptors)
271271
.flatMap(List::stream)
272272
.collect(Collectors.toMap(QueryRewriteInterceptor::getQueryName, interceptor -> {
273273
if (interceptor.getQueryName() == null) {

server/src/main/java/org/elasticsearch/plugins/SearchPlugin.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.index.query.QueryParser;
2424
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
2525
import org.elasticsearch.index.query.functionscore.ScoreFunctionParser;
26-
import org.elasticsearch.plugins.internal.rewriter.QueryRewriteInterceptor;
2726
import org.elasticsearch.search.SearchExtBuilder;
2827
import org.elasticsearch.search.aggregations.Aggregation;
2928
import org.elasticsearch.search.aggregations.AggregationBuilder;
@@ -129,14 +128,6 @@ default List<QuerySpec<?>> getQueries() {
129128
return emptyList();
130129
}
131130

132-
/**
133-
* @return Applicable {@link QueryRewriteInterceptor}s configured for this plugin.
134-
* Note: This is internal to Elasticsearch's API and not extensible by external plugins.
135-
*/
136-
default List<QueryRewriteInterceptor> getQueryRewriteInterceptors() {
137-
return emptyList();
138-
}
139-
140131
/**
141132
* The new {@link Aggregation}s added by this plugin.
142133
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.plugins.internal;
11+
12+
import org.elasticsearch.plugins.internal.rewriter.QueryRewriteInterceptor;
13+
14+
import java.util.List;
15+
16+
import static java.util.Collections.emptyList;
17+
18+
public interface InternalSearchPlugin {
19+
20+
/**
21+
* @return Applicable {@link QueryRewriteInterceptor}s configured for this plugin.
22+
* Note: This is internal to Elasticsearch's API and not extensible by external plugins.
23+
*/
24+
default List<QueryRewriteInterceptor> getQueryRewriteInterceptors() {
25+
return emptyList();
26+
}
27+
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.plugins.Plugin;
4040
import org.elasticsearch.plugins.SearchPlugin;
4141
import org.elasticsearch.plugins.SystemIndexPlugin;
42+
import org.elasticsearch.plugins.internal.InternalSearchPlugin;
4243
import org.elasticsearch.plugins.internal.rewriter.QueryRewriteInterceptor;
4344
import org.elasticsearch.rest.RestController;
4445
import org.elasticsearch.rest.RestHandler;
@@ -136,7 +137,14 @@
136137
import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceFeature.DEPRECATED_ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG;
137138
import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceFeature.ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG;
138139

139-
public class InferencePlugin extends Plugin implements ActionPlugin, ExtensiblePlugin, SystemIndexPlugin, MapperPlugin, SearchPlugin {
140+
public class InferencePlugin extends Plugin
141+
implements
142+
ActionPlugin,
143+
ExtensiblePlugin,
144+
SystemIndexPlugin,
145+
MapperPlugin,
146+
SearchPlugin,
147+
InternalSearchPlugin {
140148

141149
/**
142150
* When this setting is true the verification check that

0 commit comments

Comments
 (0)