|
23 | 23 | import org.opensearch.cluster.ClusterState;
|
24 | 24 | import org.opensearch.cluster.ClusterStateApplier;
|
25 | 25 | import org.opensearch.cluster.metadata.IndexMetadata;
|
| 26 | +import org.opensearch.cluster.metadata.IndexNameExpressionResolver; |
26 | 27 | import org.opensearch.cluster.metadata.Metadata;
|
27 | 28 | import org.opensearch.cluster.node.DiscoveryNode;
|
28 | 29 | import org.opensearch.cluster.service.ClusterManagerTaskKeys;
|
|
35 | 36 | import org.opensearch.common.xcontent.XContentHelper;
|
36 | 37 | import org.opensearch.core.action.ActionListener;
|
37 | 38 | import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
|
| 39 | +import org.opensearch.core.index.Index; |
38 | 40 | import org.opensearch.core.service.ReportingService;
|
39 | 41 | import org.opensearch.core.xcontent.NamedXContentRegistry;
|
40 | 42 | import org.opensearch.env.Environment;
|
41 | 43 | import org.opensearch.gateway.GatewayService;
|
| 44 | +import org.opensearch.index.IndexNotFoundException; |
42 | 45 | import org.opensearch.index.IndexSettings;
|
43 | 46 | import org.opensearch.index.analysis.AnalysisRegistry;
|
44 | 47 | import org.opensearch.ingest.ConfigurationUtils;
|
|
62 | 65 | /**
|
63 | 66 | * The main entry point for search pipelines. Handles CRUD operations and exposes the API to execute search pipelines
|
64 | 67 | * against requests and responses.
|
| 68 | + * |
| 69 | + * @opensearch.internal |
65 | 70 | */
|
66 | 71 | public class SearchPipelineService implements ClusterStateApplier, ReportingService<SearchPipelineInfo> {
|
67 | 72 |
|
@@ -360,7 +365,7 @@ static ClusterState innerDelete(DeleteSearchPipelineRequest request, ClusterStat
|
360 | 365 | return newState.build();
|
361 | 366 | }
|
362 | 367 |
|
363 |
| - public PipelinedRequest resolvePipeline(SearchRequest searchRequest) { |
| 368 | + public PipelinedRequest resolvePipeline(SearchRequest searchRequest, IndexNameExpressionResolver indexNameExpressionResolver) { |
364 | 369 | Pipeline pipeline = Pipeline.NO_OP_PIPELINE;
|
365 | 370 |
|
366 | 371 | if (searchRequest.source() != null && searchRequest.source().searchPipelineSource() != null) {
|
@@ -390,14 +395,27 @@ public PipelinedRequest resolvePipeline(SearchRequest searchRequest) {
|
390 | 395 | if (searchRequest.pipeline() != null) {
|
391 | 396 | // Named pipeline specified for the request
|
392 | 397 | pipelineId = searchRequest.pipeline();
|
393 |
| - } else if (state != null && searchRequest.indices() != null && searchRequest.indices().length == 1) { |
394 |
| - // Check for index default pipeline |
395 |
| - IndexMetadata indexMetadata = state.metadata().index(searchRequest.indices()[0]); |
396 |
| - if (indexMetadata != null) { |
397 |
| - Settings indexSettings = indexMetadata.getSettings(); |
398 |
| - if (IndexSettings.DEFAULT_SEARCH_PIPELINE.exists(indexSettings)) { |
399 |
| - pipelineId = IndexSettings.DEFAULT_SEARCH_PIPELINE.get(indexSettings); |
| 398 | + } else if (state != null && searchRequest.indices() != null && searchRequest.indices().length != 0) { |
| 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 | + } |
| 414 | + } |
| 415 | + } |
400 | 416 | }
|
| 417 | + } catch (IndexNotFoundException e) { |
| 418 | + logger.debug("Default pipeline not applied for {}", (Object) searchRequest.indices()); |
401 | 419 | }
|
402 | 420 | }
|
403 | 421 | if (NOOP_PIPELINE_ID.equals(pipelineId) == false) {
|
|
0 commit comments