Skip to content

Commit e393181

Browse files
committed
Handled exception
Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>
1 parent d043e85 commit e393181

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

server/src/main/java/org/opensearch/search/pipeline/SearchPipelineService.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.opensearch.core.xcontent.NamedXContentRegistry;
4242
import org.opensearch.env.Environment;
4343
import org.opensearch.gateway.GatewayService;
44+
import org.opensearch.index.IndexNotFoundException;
4445
import org.opensearch.index.IndexSettings;
4546
import org.opensearch.index.analysis.AnalysisRegistry;
4647
import org.opensearch.ingest.ConfigurationUtils;
@@ -64,6 +65,8 @@
6465
/**
6566
* The main entry point for search pipelines. Handles CRUD operations and exposes the API to execute search pipelines
6667
* against requests and responses.
68+
*
69+
* @opensearch.internal
6770
*/
6871
public class SearchPipelineService implements ClusterStateApplier, ReportingService<SearchPipelineInfo> {
6972

@@ -393,22 +396,26 @@ public PipelinedRequest resolvePipeline(SearchRequest searchRequest, IndexNameEx
393396
// Named pipeline specified for the request
394397
pipelineId = searchRequest.pipeline();
395398
} else if (state != null && searchRequest.indices() != null && searchRequest.indices().length != 0) {
396-
// Check for index default pipeline
397-
Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, searchRequest);
398-
for (Index index : concreteIndices) {
399-
IndexMetadata indexMetadata = state.metadata().index(index);
400-
if (indexMetadata != null) {
401-
Settings indexSettings = indexMetadata.getSettings();
402-
if (IndexSettings.DEFAULT_SEARCH_PIPELINE.exists(indexSettings)) {
403-
String currentPipelineId = IndexSettings.DEFAULT_SEARCH_PIPELINE.get(indexSettings);
404-
if (NOOP_PIPELINE_ID.equals(pipelineId)) {
405-
pipelineId = currentPipelineId;
406-
} else if (pipelineId.equals(currentPipelineId) == false) {
407-
pipelineId = NOOP_PIPELINE_ID;
408-
break;
399+
try {
400+
// Check for index default pipeline
401+
Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, searchRequest);
402+
for (Index index : concreteIndices) {
403+
IndexMetadata indexMetadata = state.metadata().index(index);
404+
if (indexMetadata != null) {
405+
Settings indexSettings = indexMetadata.getSettings();
406+
if (IndexSettings.DEFAULT_SEARCH_PIPELINE.exists(indexSettings)) {
407+
String currentPipelineId = IndexSettings.DEFAULT_SEARCH_PIPELINE.get(indexSettings);
408+
if (NOOP_PIPELINE_ID.equals(pipelineId)) {
409+
pipelineId = currentPipelineId;
410+
} else if (!pipelineId.equals(currentPipelineId)) {
411+
pipelineId = NOOP_PIPELINE_ID;
412+
break;
413+
}
409414
}
410415
}
411416
}
417+
} catch (IndexNotFoundException e) {
418+
logger.debug("Default pipeline not applied for {}", (Object) searchRequest.indices());
412419
}
413420
}
414421
if (NOOP_PIPELINE_ID.equals(pipelineId) == false) {

server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,4 +1664,39 @@ public void testNoIndexResolveIndexDefaultPipeline() throws Exception {
16641664
assertEquals(5, pipelinedRequest.source().size());
16651665
}
16661666

1667+
public void testInvalidIndexResolveIndexDefaultPipeline() throws Exception {
1668+
SearchPipelineService service = createWithProcessors();
1669+
1670+
SearchPipelineMetadata metadata = new SearchPipelineMetadata(
1671+
Map.of(
1672+
"p1",
1673+
new PipelineConfiguration(
1674+
"p1",
1675+
new BytesArray("{\"request_processors\" : [ { \"scale_request_size\": { \"scale\" : 2 } } ] }"),
1676+
MediaTypeRegistry.JSON
1677+
)
1678+
)
1679+
);
1680+
Settings defaultPipelineSetting = Settings.builder()
1681+
.put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
1682+
.put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
1683+
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), Version.CURRENT)
1684+
.put(IndexSettings.DEFAULT_SEARCH_PIPELINE.getKey(), "p1")
1685+
.build();
1686+
IndexMetadata indexMetadata = new IndexMetadata.Builder("my_index").settings(defaultPipelineSetting).build();
1687+
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
1688+
ClusterState previousState = clusterState;
1689+
clusterState = ClusterState.builder(clusterState)
1690+
.metadata(Metadata.builder().put(indexMetadata, false).putCustom(SearchPipelineMetadata.TYPE, metadata))
1691+
.build();
1692+
1693+
ClusterChangedEvent cce = new ClusterChangedEvent("", clusterState, previousState);
1694+
service.applyClusterState(cce);
1695+
1696+
SearchRequest searchRequest = new SearchRequest("xyz").source(SearchSourceBuilder.searchSource().size(5));
1697+
PipelinedRequest pipelinedRequest = syncTransformRequest(service.resolvePipeline(searchRequest, indexNameExpressionResolver));
1698+
assertEquals("_none", pipelinedRequest.getPipeline().getId());
1699+
assertEquals(5, pipelinedRequest.source().size());
1700+
}
1701+
16671702
}

0 commit comments

Comments
 (0)