diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptProcessor.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java similarity index 91% rename from modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptProcessor.java rename to modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java index 41ebb21406281..015411e0701a4 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptProcessor.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java @@ -38,7 +38,7 @@ * Processor that evaluates a script with a search request in its context * and then returns the modified search request. */ -public final class ScriptProcessor extends AbstractProcessor implements SearchRequestProcessor { +public final class ScriptRequestProcessor extends AbstractProcessor implements SearchRequestProcessor { /** * Key to reference this processor type from a search pipeline. */ @@ -57,7 +57,7 @@ public final class ScriptProcessor extends AbstractProcessor implements SearchRe * @param precompiledSearchScript The {@link Script} precompiled * @param scriptService The {@link ScriptService} used to execute the script. */ - ScriptProcessor( + ScriptRequestProcessor( String tag, String description, Script script, @@ -124,9 +124,9 @@ SearchScript getPrecompiledSearchScript() { } /** - * Factory class for creating {@link ScriptProcessor}. + * Factory class for creating {@link ScriptRequestProcessor}. */ - public static final class Factory implements Processor.Factory { + public static final class Factory implements Processor.Factory { private final ScriptService scriptService; /** @@ -139,18 +139,18 @@ public Factory(ScriptService scriptService) { } /** - * Creates a new instance of {@link ScriptProcessor}. + * Creates a new instance of {@link ScriptRequestProcessor}. * * @param registry The registry of processor factories. * @param processorTag The processor's tag. * @param description The processor's description. * @param config The configuration options for the processor. - * @return The created {@link ScriptProcessor} instance. + * @return The created {@link ScriptRequestProcessor} instance. * @throws Exception if an error occurs during the creation process. */ @Override - public ScriptProcessor create( - Map registry, + public ScriptRequestProcessor create( + Map> registry, String processorTag, String description, Map config @@ -175,7 +175,7 @@ public ScriptProcessor create( } catch (ScriptException e) { throw newConfigurationException(TYPE, processorTag, null, e); } - return new ScriptProcessor(processorTag, description, script, searchScript, scriptService); + return new ScriptRequestProcessor(processorTag, description, script, searchScript, scriptService); } } } diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SearchPipelineCommonModulePlugin.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SearchPipelineCommonModulePlugin.java index 2aa366ae9758c..dc25de460fdba 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SearchPipelineCommonModulePlugin.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SearchPipelineCommonModulePlugin.java @@ -37,8 +37,8 @@ public Map> getRequestProcesso return Map.of( FilterQueryRequestProcessor.TYPE, new FilterQueryRequestProcessor.Factory(parameters.namedXContentRegistry), - ScriptProcessor.TYPE, - new ScriptProcessor.Factory(parameters.scriptService) + ScriptRequestProcessor.TYPE, + new ScriptRequestProcessor.Factory(parameters.scriptService) ); } diff --git a/modules/search-pipeline-common/src/test/java/org/opensearch/search/pipeline/common/ScriptProcessorTests.java b/modules/search-pipeline-common/src/test/java/org/opensearch/search/pipeline/common/ScriptRequestProcessorTests.java similarity index 93% rename from modules/search-pipeline-common/src/test/java/org/opensearch/search/pipeline/common/ScriptProcessorTests.java rename to modules/search-pipeline-common/src/test/java/org/opensearch/search/pipeline/common/ScriptRequestProcessorTests.java index d2a8c0018dde2..2fb3b2345e7e2 100644 --- a/modules/search-pipeline-common/src/test/java/org/opensearch/search/pipeline/common/ScriptProcessorTests.java +++ b/modules/search-pipeline-common/src/test/java/org/opensearch/search/pipeline/common/ScriptRequestProcessorTests.java @@ -29,7 +29,7 @@ import static org.hamcrest.core.Is.is; import java.util.concurrent.TimeUnit; -public class ScriptProcessorTests extends OpenSearchTestCase { +public class ScriptRequestProcessorTests extends OpenSearchTestCase { private ScriptService scriptService; private Script script; @@ -82,7 +82,7 @@ public void setupScripting() { } public void testScriptingWithoutPrecompiledScriptFactory() throws Exception { - ScriptProcessor processor = new ScriptProcessor(randomAlphaOfLength(10), null, script, null, scriptService); + ScriptRequestProcessor processor = new ScriptRequestProcessor(randomAlphaOfLength(10), null, script, null, scriptService); SearchRequest searchRequest = new SearchRequest(); searchRequest.source(createSearchSourceBuilder()); @@ -92,7 +92,7 @@ public void testScriptingWithoutPrecompiledScriptFactory() throws Exception { } public void testScriptingWithPrecompiledIngestScript() throws Exception { - ScriptProcessor processor = new ScriptProcessor(randomAlphaOfLength(10), null, script, searchScript, scriptService); + ScriptRequestProcessor processor = new ScriptRequestProcessor(randomAlphaOfLength(10), null, script, searchScript, scriptService); SearchRequest searchRequest = new SearchRequest(); searchRequest.source(createSearchSourceBuilder()); diff --git a/modules/search-pipeline-common/src/yamlRestTest/resources/rest-api-spec/test/search_pipeline/50_script_processor.yml b/modules/search-pipeline-common/src/yamlRestTest/resources/rest-api-spec/test/search_pipeline/50_script_processor.yml index bba52285fd58d..c70f05ff7f115 100644 --- a/modules/search-pipeline-common/src/yamlRestTest/resources/rest-api-spec/test/search_pipeline/50_script_processor.yml +++ b/modules/search-pipeline-common/src/yamlRestTest/resources/rest-api-spec/test/search_pipeline/50_script_processor.yml @@ -94,3 +94,49 @@ teardown: - is_false: hits.hits.0._primary_term - is_false: hits.hits.1._primary_term - is_false: profile + +--- +"Test unsupported operations in script processor": + - do: + search_pipeline.put: + id: "my_pipeline" + body: > + { + "description": "_description", + "request_processors": [ + { + "script" : { + "lang": "painless", + "source" : "int a = ctx.dummy;" + } + } + ] + } + - match: { acknowledged: true } + + - do: + index: + index: test + id: 1 + body: { + "field": "foo" + } + - do: + index: + index: test + id: 2 + body: { + "field": "value" + } + + - do: + indices.refresh: + index: test + + - do: + catch: bad_request + search: + index: test + search_pipeline: "my_pipeline" + body: { } + - match: { status: 400 }