-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Expose Engine.Searcher provider to ingest plugins. #41010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d5f8e1d
5800d23
a867fd6
d9eeae7
e0f5384
340b0c0
7fbbd2f
69dcf44
15b0606
6cdd8df
cafaf5d
3c9afb4
43a4725
fc939ef
8d88d6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,11 +30,13 @@ | |
import org.elasticsearch.action.index.IndexRequest; | ||
import org.elasticsearch.action.ingest.DeletePipelineRequest; | ||
import org.elasticsearch.action.ingest.PutPipelineRequest; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.cluster.AckedClusterStateUpdateTask; | ||
import org.elasticsearch.cluster.ClusterChangedEvent; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.ClusterStateApplier; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
|
@@ -45,8 +47,12 @@ | |
import org.elasticsearch.common.xcontent.XContentHelper; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.gateway.GatewayService; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexService; | ||
import org.elasticsearch.index.VersionType; | ||
import org.elasticsearch.index.analysis.AnalysisRegistry; | ||
import org.elasticsearch.index.shard.IndexShard; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.plugins.IngestPlugin; | ||
import org.elasticsearch.script.ScriptService; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
|
@@ -86,17 +92,43 @@ public class IngestService implements ClusterStateApplier { | |
|
||
public IngestService(ClusterService clusterService, ThreadPool threadPool, | ||
Environment env, ScriptService scriptService, AnalysisRegistry analysisRegistry, | ||
List<IngestPlugin> ingestPlugins) { | ||
List<IngestPlugin> ingestPlugins, IndicesService indicesService) { | ||
this.clusterService = clusterService; | ||
this.scriptService = scriptService; | ||
final IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(); | ||
this.processorFactories = processorFactories( | ||
ingestPlugins, | ||
new Processor.Parameters( | ||
env, scriptService, analysisRegistry, | ||
threadPool.getThreadContext(), threadPool::relativeTimeInMillis, | ||
(delay, command) -> threadPool.schedule( | ||
command, TimeValue.timeValueMillis(delay), ThreadPool.Names.GENERIC | ||
), this | ||
), this, indexExpression -> { | ||
ClusterState state = clusterService.state(); | ||
Index[] resolvedIndices = resolver.concreteIndices(state, IndicesOptions.STRICT_EXPAND_OPEN, indexExpression); | ||
if (resolvedIndices.length != 1) { | ||
throw new IllegalStateException("expression [" + indexExpression + "] can only point to a single concrete index"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we prevent filtered aliases too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that makes sense. There is no guarantee that they will be applied in an ingest processor. I will fail with an error if an alias has a filter. |
||
Index index = resolvedIndices[0]; | ||
|
||
// check if indexExpression matches with an alias that has a filter | ||
// There is no guarantee that alias filters are applied, so fail if this is the case. | ||
Set<String> indicesAndAliases = resolver.resolveExpressions(state, indexExpression); | ||
String[] aliasesWithFilter = resolver.filteringAliases(state, index.getName(), indicesAndAliases); | ||
if (aliasesWithFilter != null && aliasesWithFilter.length > 0) { | ||
throw new IllegalStateException("expression [" + indexExpression + "] points an alias with a filter"); | ||
} | ||
|
||
IndexService indexService = indicesService.indexServiceSafe(index); | ||
int numShards = indexService.getMetaData().getNumberOfShards(); | ||
if (numShards != 1) { | ||
throw new IllegalStateException("index [" + index.getName() + "] must have 1 shard, but has " + numShards + | ||
" shards"); | ||
} | ||
|
||
IndexShard indexShard = indexService.getShard(0); | ||
return indexShard.acquireSearcher("ingest"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for my education, does this create a new searcher or give you back a pre-existing one ? If the former, do we need to do anything with the existing one w/r/t disabling refreshes ? (sorry if this a bogus question, I don't have much experience at this level). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This always creates a new searcher. The code invoking this should be aware of this and make sure to close it after it is done with the searcher. In our case we will need to reuse the searcher from an ingest processor. We don't want to invoke this every time an enrich processor is invoked. |
||
} | ||
) | ||
); | ||
this.threadPool = threadPool; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use
indexServiceSafe
?