From 6a10b80e6657896579bc3ad25b5006c4c0c58bbc Mon Sep 17 00:00:00 2001 From: Owais Kazi Date: Thu, 18 Apr 2024 10:50:42 -0700 Subject: [PATCH] Addressed PR comments Signed-off-by: Owais Kazi --- .../pipeline/SearchPipelineService.java | 2 +- .../pipeline/SearchPipelineServiceTests.java | 39 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/opensearch/search/pipeline/SearchPipelineService.java b/server/src/main/java/org/opensearch/search/pipeline/SearchPipelineService.java index 2bae68b7a25ba..9e4341347d8a8 100644 --- a/server/src/main/java/org/opensearch/search/pipeline/SearchPipelineService.java +++ b/server/src/main/java/org/opensearch/search/pipeline/SearchPipelineService.java @@ -392,7 +392,7 @@ public PipelinedRequest resolvePipeline(SearchRequest searchRequest, IndexNameEx if (searchRequest.pipeline() != null) { // Named pipeline specified for the request pipelineId = searchRequest.pipeline(); - } else if (state != null && searchRequest.indices() != null) { + } else if (state != null && searchRequest.indices() != null && searchRequest.indices().length != 0) { // Check for index default pipeline Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, searchRequest); for (Index index : concreteIndices) { diff --git a/server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java b/server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java index 4b9daadeda02f..0788b2b483a96 100644 --- a/server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java +++ b/server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java @@ -115,10 +115,10 @@ private static IndexMetadata.Builder indexBuilder(String index) { } private static IndexMetadata.Builder indexBuilder(String index, Settings additionalSettings) { - return IndexMetadata.builder(index).settings(settings(additionalSettings)); + return IndexMetadata.builder(index).settings(addAdditionalSettings(additionalSettings)); } - private static Settings.Builder settings(Settings additionalSettings) { + private static Settings.Builder addAdditionalSettings(Settings additionalSettings) { return settings(Version.CURRENT).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(additionalSettings); @@ -1629,4 +1629,39 @@ public void testDifferentDefaultPipelineForMultipleIndices() throws Exception { assertEquals(5, pipelinedRequest.source().size()); } + public void testNoIndexResolveIndexDefaultPipeline() throws Exception { + SearchPipelineService service = createWithProcessors(); + + SearchPipelineMetadata metadata = new SearchPipelineMetadata( + Map.of( + "p1", + new PipelineConfiguration( + "p1", + new BytesArray("{\"request_processors\" : [ { \"scale_request_size\": { \"scale\" : 2 } } ] }"), + MediaTypeRegistry.JSON + ) + ) + ); + Settings defaultPipelineSetting = Settings.builder() + .put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1) + .put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0) + .put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), Version.CURRENT) + .put(IndexSettings.DEFAULT_SEARCH_PIPELINE.getKey(), "p1") + .build(); + IndexMetadata indexMetadata = new IndexMetadata.Builder("my_index").settings(defaultPipelineSetting).build(); + ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build(); + ClusterState previousState = clusterState; + clusterState = ClusterState.builder(clusterState) + .metadata(Metadata.builder().put(indexMetadata, false).putCustom(SearchPipelineMetadata.TYPE, metadata)) + .build(); + + ClusterChangedEvent cce = new ClusterChangedEvent("", clusterState, previousState); + service.applyClusterState(cce); + + SearchRequest searchRequest = new SearchRequest().source(SearchSourceBuilder.searchSource().size(5)); + PipelinedRequest pipelinedRequest = syncTransformRequest(service.resolvePipeline(searchRequest, indexNameExpressionResolver)); + assertEquals("_none", pipelinedRequest.getPipeline().getId()); + assertEquals(5, pipelinedRequest.source().size()); + } + }