|
30 | 30 | import org.elasticsearch.action.index.IndexRequest;
|
31 | 31 | import org.elasticsearch.action.ingest.DeletePipelineRequest;
|
32 | 32 | import org.elasticsearch.action.ingest.PutPipelineRequest;
|
| 33 | +import org.elasticsearch.action.support.IndicesOptions; |
33 | 34 | import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
34 | 35 | import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
|
35 | 36 | import org.elasticsearch.cluster.ClusterChangedEvent;
|
36 | 37 | import org.elasticsearch.cluster.ClusterState;
|
37 | 38 | import org.elasticsearch.cluster.ClusterStateApplier;
|
| 39 | +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; |
38 | 40 | import org.elasticsearch.cluster.metadata.MetaData;
|
39 | 41 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
40 | 42 | import org.elasticsearch.cluster.service.ClusterService;
|
|
45 | 47 | import org.elasticsearch.common.xcontent.XContentHelper;
|
46 | 48 | import org.elasticsearch.env.Environment;
|
47 | 49 | import org.elasticsearch.gateway.GatewayService;
|
| 50 | +import org.elasticsearch.index.Index; |
| 51 | +import org.elasticsearch.index.IndexService; |
48 | 52 | import org.elasticsearch.index.VersionType;
|
49 | 53 | import org.elasticsearch.index.analysis.AnalysisRegistry;
|
| 54 | +import org.elasticsearch.index.shard.IndexShard; |
| 55 | +import org.elasticsearch.indices.IndicesService; |
50 | 56 | import org.elasticsearch.plugins.IngestPlugin;
|
51 | 57 | import org.elasticsearch.script.ScriptService;
|
52 | 58 | import org.elasticsearch.threadpool.ThreadPool;
|
@@ -86,17 +92,43 @@ public class IngestService implements ClusterStateApplier {
|
86 | 92 |
|
87 | 93 | public IngestService(ClusterService clusterService, ThreadPool threadPool,
|
88 | 94 | Environment env, ScriptService scriptService, AnalysisRegistry analysisRegistry,
|
89 |
| - List<IngestPlugin> ingestPlugins) { |
| 95 | + List<IngestPlugin> ingestPlugins, IndicesService indicesService) { |
90 | 96 | this.clusterService = clusterService;
|
91 | 97 | this.scriptService = scriptService;
|
| 98 | + final IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(); |
92 | 99 | this.processorFactories = processorFactories(
|
93 | 100 | ingestPlugins,
|
94 | 101 | new Processor.Parameters(
|
95 | 102 | env, scriptService, analysisRegistry,
|
96 | 103 | threadPool.getThreadContext(), threadPool::relativeTimeInMillis,
|
97 | 104 | (delay, command) -> threadPool.schedule(
|
98 | 105 | command, TimeValue.timeValueMillis(delay), ThreadPool.Names.GENERIC
|
99 |
| - ), this |
| 106 | + ), this, indexExpression -> { |
| 107 | + ClusterState state = clusterService.state(); |
| 108 | + Index[] resolvedIndices = resolver.concreteIndices(state, IndicesOptions.STRICT_EXPAND_OPEN, indexExpression); |
| 109 | + if (resolvedIndices.length != 1) { |
| 110 | + throw new IllegalStateException("expression [" + indexExpression + "] can only point to a single concrete index"); |
| 111 | + } |
| 112 | + Index index = resolvedIndices[0]; |
| 113 | + |
| 114 | + // check if indexExpression matches with an alias that has a filter |
| 115 | + // There is no guarantee that alias filters are applied, so fail if this is the case. |
| 116 | + Set<String> indicesAndAliases = resolver.resolveExpressions(state, indexExpression); |
| 117 | + String[] aliasesWithFilter = resolver.filteringAliases(state, index.getName(), indicesAndAliases); |
| 118 | + if (aliasesWithFilter != null && aliasesWithFilter.length > 0) { |
| 119 | + throw new IllegalStateException("expression [" + indexExpression + "] points an alias with a filter"); |
| 120 | + } |
| 121 | + |
| 122 | + IndexService indexService = indicesService.indexServiceSafe(index); |
| 123 | + int numShards = indexService.getMetaData().getNumberOfShards(); |
| 124 | + if (numShards != 1) { |
| 125 | + throw new IllegalStateException("index [" + index.getName() + "] must have 1 shard, but has " + numShards + |
| 126 | + " shards"); |
| 127 | + } |
| 128 | + |
| 129 | + IndexShard indexShard = indexService.getShard(0); |
| 130 | + return indexShard.acquireSearcher("ingest"); |
| 131 | + } |
100 | 132 | )
|
101 | 133 | );
|
102 | 134 | this.threadPool = threadPool;
|
|
0 commit comments