Skip to content

Commit

Permalink
Move query interceptor to an internal plugin interface (elastic#120308)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjernst authored Jan 17, 2025
1 parent 4c1c3b8 commit ac687e0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
exports org.elasticsearch.action.downsample;
exports org.elasticsearch.plugins.internal
to
org.elasticsearch.inference,
org.elasticsearch.metering,
org.elasticsearch.stateless,
org.elasticsearch.settings.secure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.elasticsearch.plugins.EnginePlugin;
import org.elasticsearch.plugins.IndexStorePlugin;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.plugins.internal.InternalSearchPlugin;
import org.elasticsearch.plugins.internal.rewriter.QueryRewriteInterceptor;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
Expand Down Expand Up @@ -266,8 +266,8 @@ public IndicesService build() {
.flatMap(m -> m.entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

var queryRewriteInterceptors = pluginsService.filterPlugins(SearchPlugin.class)
.map(SearchPlugin::getQueryRewriteInterceptors)
var queryRewriteInterceptors = pluginsService.filterPlugins(InternalSearchPlugin.class)
.map(InternalSearchPlugin::getQueryRewriteInterceptors)
.flatMap(List::stream)
.collect(Collectors.toMap(QueryRewriteInterceptor::getQueryName, interceptor -> {
if (interceptor.getQueryName() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.index.query.QueryParser;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionParser;
import org.elasticsearch.plugins.internal.rewriter.QueryRewriteInterceptor;
import org.elasticsearch.search.SearchExtBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilder;
Expand Down Expand Up @@ -129,14 +128,6 @@ default List<QuerySpec<?>> getQueries() {
return emptyList();
}

/**
* @return Applicable {@link QueryRewriteInterceptor}s configured for this plugin.
* Note: This is internal to Elasticsearch's API and not extensible by external plugins.
*/
default List<QueryRewriteInterceptor> getQueryRewriteInterceptors() {
return emptyList();
}

/**
* The new {@link Aggregation}s added by this plugin.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.plugins.internal;

import org.elasticsearch.plugins.internal.rewriter.QueryRewriteInterceptor;

import java.util.List;

import static java.util.Collections.emptyList;

public interface InternalSearchPlugin {

/**
* @return Applicable {@link QueryRewriteInterceptor}s configured for this plugin.
* Note: This is internal to Elasticsearch's API and not extensible by external plugins.
*/
default List<QueryRewriteInterceptor> getQueryRewriteInterceptors() {
return emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.plugins.SystemIndexPlugin;
import org.elasticsearch.plugins.internal.InternalSearchPlugin;
import org.elasticsearch.plugins.internal.rewriter.QueryRewriteInterceptor;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
Expand Down Expand Up @@ -136,7 +137,14 @@
import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceFeature.DEPRECATED_ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG;
import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceFeature.ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG;

public class InferencePlugin extends Plugin implements ActionPlugin, ExtensiblePlugin, SystemIndexPlugin, MapperPlugin, SearchPlugin {
public class InferencePlugin extends Plugin
implements
ActionPlugin,
ExtensiblePlugin,
SystemIndexPlugin,
MapperPlugin,
SearchPlugin,
InternalSearchPlugin {

/**
* When this setting is true the verification check that
Expand Down

0 comments on commit ac687e0

Please sign in to comment.