Module org.elasticsearch.server
Class IndexNameExpressionResolver
java.lang.Object
org.elasticsearch.cluster.metadata.IndexNameExpressionResolver
This class main focus is to resolve multi-syntax target expressions to resources or concrete indices. This resolution is influenced
by IndicesOptions and other flags passed through the method call. Examples of the functionality it provides:
- Resolve expressions to concrete indices
- Resolve expressions to data stream names
- Resolve expressions to resources (meaning indices, data streams and aliases)
Note: This class is performance sensitive, so we pay extra attention on the data structure usage and we avoid streams and iterators
when possible in favor of the classic for-i loops.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final classResolves a date math expression based on the requested time.static final recordThis represents a resolved expression in the form of the name of a resource in the cluster and a potential selector which defines which part of the resource the expression is targeting.static final classstatic final classIn this class we collect the system access relevant code. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionIndexNameExpressionResolver(ThreadContext threadContext, SystemIndices systemIndices) -
Method Summary
Modifier and TypeMethodDescriptionString[]allIndexAliases(ClusterState state, String index, Set<IndexNameExpressionResolver.ResolvedExpression> resolvedExpressions) Iterates through the list of indices and selects the effective list of all aliases for the given index.static voidassertExpressionHasNullOrDataSelector(String expression) static StringcombineSelector(String baseExpression, IndexComponentSelector selectorExpression) static StringcombineSelectorExpression(String baseExpression, String selectorExpression) String[]concreteIndexNames(ClusterState state, IndicesRequest request) Same asconcreteIndexNames(ClusterState, IndicesOptions, String...), but the index expressions and options are encapsulated in the specified request.String[]concreteIndexNames(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions) String[]concreteIndexNames(ClusterState state, IndicesOptions options, String... indexExpressions) Translates the provided index expression into actual concrete indices, properly deduplicated.String[]concreteIndexNames(ClusterState state, IndicesOptions options, IndicesRequest request) String[]concreteIndexNamesWithSystemIndexAccess(ClusterState state, IndicesRequest request) Same asconcreteIndexNames(ClusterState, IndicesRequest), but access to system indices is always allowed.Index[]concreteIndices(ClusterState state, IndicesRequest request) Same asconcreteIndices(ClusterState, IndicesOptions, String...), but the index expressions and options are encapsulated in the specified request and resolves data streams.Index[]concreteIndices(ClusterState state, IndicesRequest request, long startTime) Translates the provided index expression into actual concrete indices, properly deduplicated.Index[]concreteIndices(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions) Index[]concreteIndices(ClusterState state, IndicesOptions options, String... indexExpressions) Translates the provided index expression into actual concrete indices, properly deduplicated.concreteSingleIndex(ClusterState state, IndicesRequest request) Utility method that allows to resolve an index expression to its corresponding single concrete index.concreteWriteIndex(ClusterState state, IndicesRequest request) Utility method that allows to resolve an index expression to its corresponding single write index.concreteWriteIndex(ClusterState state, IndicesOptions options, String index, boolean allowNoIndices, boolean includeDataStreams) Utility method that allows to resolve an index expression to its corresponding single write index.dataStreamNames(ClusterState state, IndicesOptions options, String... indexExpressions) dataStreams(ClusterState state, IndicesOptions options, String... indexExpressions) String[]filteringAliases(ClusterState state, String index, Set<IndexNameExpressionResolver.ResolvedExpression> resolvedExpressions) Iterates through the list of indices and selects the effective list of filtering aliases for the given index.Determines the right predicate based on thegetSystemIndexAccessLevel().org.apache.lucene.util.automaton.AutomatonbooleanhasIndexAbstraction(String indexAbstraction, ClusterState state) static booleanhasSelector(String expression, IndexComponentSelector selector) static booleanhasSelectorSuffix(String expression) String[]indexAliases(ClusterState state, String index, Predicate<AliasMetadata> requiredAlias, BiPredicate<DataStreamAlias, Boolean> requiredDataStreamAlias, boolean skipIdentity, Set<IndexNameExpressionResolver.ResolvedExpression> resolvedExpressions) Iterates through the list of indices and selects the effective list of required aliases for the given index.static booleanisAllIndices(Collection<String> aliasesOrIndices) Identifies whether the array containing index names given as argument refers to all indices The empty or null array identifies all indicesstatic <T> booleanisAllIndices(Collection<T> aliasesOrIndices, Function<T, String> resourceGetter) Identifies whether the array containing objects with index names given as argument refers to all indices The empty or null array identifies all indicesstatic booleanisAllIndicesExpression(Collection<IndexNameExpressionResolver.ResolvedExpression> aliasesOrIndices) Identifies whether the array containing index names given as argument refers to all indices The empty or null array identifies all indicesstatic booleanisNoneExpression(String[] expressions) Identifies if this expression list is *,-* which effectively means a request that requests no indices.static StringresolveDateMathExpression(String dateExpression) static StringresolveDateMathExpression(String dateExpression, long time) resolveExpressions(ClusterState state, String... expressions) Resolve an array of expressions to the set of indices and aliases that these expressions match.resolveExpressions(ClusterState state, IndicesOptions indicesOptions, boolean preserveDataStreams, String... expressions) Resolve the expression to the set of indices, aliases, and, optionally, datastreams that the expression matches.protected static Collection<IndexNameExpressionResolver.ResolvedExpression> resolveExpressionsToResources(IndexNameExpressionResolver.Context context, String... expressions) Resolve the expression to the set of indices, aliases, and, optionally, data streams that the expression matches.resolveSearchRouting(ClusterState state, String routing, String... expressions) Resolves the search routing if in the expression aliases are used.resolveSearchRoutingAllIndices(Metadata metadata, String routing) Sets the same routing for all indicesresolveWriteIndexAbstraction(ClusterState state, DocWriteRequest<?> request) ReturnsIndexAbstractioninstance for the provided write request.static booleanshouldIncludeFailureIndices(IndicesOptions indicesOptions, IndexComponentSelector expressionSelector) static booleanshouldIncludeRegularIndices(IndicesOptions indicesOptions, IndexComponentSelector expressionSelector) splitSelectorExpression(String expression)
-
Field Details
-
EXCLUDED_DATA_STREAMS_KEY
- See Also:
-
SYSTEM_INDEX_ENFORCEMENT_INDEX_VERSION
-
-
Constructor Details
-
IndexNameExpressionResolver
-
-
Method Details
-
concreteIndexNames
Same asconcreteIndexNames(ClusterState, IndicesOptions, String...), but the index expressions and options are encapsulated in the specified request. -
concreteIndexNamesWithSystemIndexAccess
Same asconcreteIndexNames(ClusterState, IndicesRequest), but access to system indices is always allowed. -
concreteIndices
Same asconcreteIndices(ClusterState, IndicesOptions, String...), but the index expressions and options are encapsulated in the specified request and resolves data streams. -
concreteIndexNames
public String[] concreteIndexNames(ClusterState state, IndicesOptions options, String... indexExpressions) Translates the provided index expression into actual concrete indices, properly deduplicated.- Parameters:
state- the cluster state containing all the data to resolve to expressions to concrete indicesoptions- defines how the aliases or indices need to be resolved to concrete indicesindexExpressions- expressions that can be resolved to alias or index names.- Returns:
- the resolved concrete indices based on the cluster state, indices options and index expressions
- Throws:
IndexNotFoundException- if one of the index expressions is pointing to a missing index or alias and the provided indices options in the context don't allow such a case, or if the final result of the indices resolution contains no indices and the indices options in the context don't allow such a case.IllegalArgumentException- if one of the aliases resolve to multiple indices and the provided indices options in the context don't allow such a case; if a remote index is requested.
-
concreteIndexNames
public String[] concreteIndexNames(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions) -
concreteIndexNames
public String[] concreteIndexNames(ClusterState state, IndicesOptions options, IndicesRequest request) -
dataStreamNames
public List<String> dataStreamNames(ClusterState state, IndicesOptions options, String... indexExpressions) -
dataStreams
public List<IndexNameExpressionResolver.ResolvedExpression> dataStreams(ClusterState state, IndicesOptions options, String... indexExpressions) -
resolveWriteIndexAbstraction
public IndexAbstraction resolveWriteIndexAbstraction(ClusterState state, DocWriteRequest<?> request) ReturnsIndexAbstractioninstance for the provided write request. This instance isn't fully resolved, meaning thatIndexAbstraction.getWriteIndex()should be invoked in order to get concrete write index.- Parameters:
state- The cluster staterequest- The provided write request- Returns:
IndexAbstractioninstance for the provided write request
-
resolveExpressionsToResources
protected static Collection<IndexNameExpressionResolver.ResolvedExpression> resolveExpressionsToResources(IndexNameExpressionResolver.Context context, String... expressions) Resolve the expression to the set of indices, aliases, and, optionally, data streams that the expression matches. If istrue, data streams that are covered by the wildcards from the are returned as-is, without expanding them further to their respective backing indices. -
concreteIndices
public Index[] concreteIndices(ClusterState state, IndicesOptions options, String... indexExpressions) Translates the provided index expression into actual concrete indices, properly deduplicated.- Parameters:
state- the cluster state containing all the data to resolve to expressions to concrete indicesoptions- defines how the aliases or indices need to be resolved to concrete indicesindexExpressions- expressions that can be resolved to alias or index names.- Returns:
- the resolved concrete indices based on the cluster state, indices options and index expressions
- Throws:
IndexNotFoundException- if one of the index expressions is pointing to a missing index or alias and the provided indices options in the context don't allow such a case, or if the final result of the indices resolution contains no indices and the indices options in the context don't allow such a case.IllegalArgumentException- if one of the aliases resolve to multiple indices and the provided indices options in the context don't allow such a case; if a remote index is requested.
-
concreteIndices
public Index[] concreteIndices(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions) -
concreteIndices
Translates the provided index expression into actual concrete indices, properly deduplicated.- Parameters:
state- the cluster state containing all the data to resolve to expressions to concrete indicesrequest- request containing expressions that can be resolved to alias, index, or data stream names.startTime- The start of the request where concrete indices is being invoked for- Returns:
- the resolved concrete indices based on the cluster state, indices options and index expressions provided indices options in the context don't allow such a case, or if the final result of the indices resolution contains no indices and the indices options in the context don't allow such a case.
- Throws:
IllegalArgumentException- if one of the aliases resolve to multiple indices and the provided indices options in the context don't allow such a case; if a remote index is requested.
-
shouldIncludeRegularIndices
public static boolean shouldIncludeRegularIndices(IndicesOptions indicesOptions, IndexComponentSelector expressionSelector) -
shouldIncludeFailureIndices
public static boolean shouldIncludeFailureIndices(IndicesOptions indicesOptions, IndexComponentSelector expressionSelector) -
concreteSingleIndex
Utility method that allows to resolve an index expression to its corresponding single concrete index. Callers should make sure they provide properIndicesOptionsthat require a single index as a result. The indices resolution must in fact return a single index when using this method, anIllegalArgumentExceptiongets thrown otherwise.- Parameters:
state- the cluster state containing all the data to resolve to expression to a concrete indexrequest- The request that defines how the an alias or an index need to be resolved to a concrete index and the expression that can be resolved to an alias or an index name.- Returns:
- the concrete index obtained as a result of the index resolution
- Throws:
IllegalArgumentException- if the index resolution returns more than one index; if a remote index is requested.
-
concreteWriteIndex
Utility method that allows to resolve an index expression to its corresponding single write index.- Parameters:
state- the cluster state containing all the data to resolve to expression to a concrete indexrequest- The request that defines how an alias or an index need to be resolved to a concrete index and the expression that can be resolved to an alias or an index name.- Returns:
- the write index obtained as a result of the index resolution
- Throws:
IllegalArgumentException- if the index resolution does not lead to an index, or leads to more than one index
-
concreteWriteIndex
public Index concreteWriteIndex(ClusterState state, IndicesOptions options, String index, boolean allowNoIndices, boolean includeDataStreams) Utility method that allows to resolve an index expression to its corresponding single write index.- Parameters:
state- the cluster state containing all the data to resolve to expression to a concrete indexoptions- defines how the aliases or indices need to be resolved to concrete indicesindex- index that can be resolved to alias or index name.allowNoIndices- whether to allow resolve to no indexincludeDataStreams- Whether data streams should be included in the evaluation.- Returns:
- the write index obtained as a result of the index resolution or null if no index
- Throws:
IllegalArgumentException- if the index resolution does not lead to an index, or leads to more than one index, as well as if a remote index is requested.
-
hasIndexAbstraction
- Returns:
- whether the specified index, data stream or alias exists. If the data stream, index or alias contains date math then that is resolved too.
-
hasSelectorSuffix
- Returns:
- True if the provided expression contains the
::character sequence.
-
hasSelector
-
splitSelectorExpression
- Returns:
- If the specified string is a selector expression then this method returns the base expression and its selector part.
-
combineSelector
public static String combineSelector(String baseExpression, @Nullable IndexComponentSelector selectorExpression) -
combineSelectorExpression
-
assertExpressionHasNullOrDataSelector
-
resolveExpressions
public Set<IndexNameExpressionResolver.ResolvedExpression> resolveExpressions(ClusterState state, String... expressions) Resolve an array of expressions to the set of indices and aliases that these expressions match. -
resolveExpressions
public Set<IndexNameExpressionResolver.ResolvedExpression> resolveExpressions(ClusterState state, IndicesOptions indicesOptions, boolean preserveDataStreams, String... expressions) Resolve the expression to the set of indices, aliases, and, optionally, datastreams that the expression matches. If istrue, datastreams that are covered by the wildcards from the are returned as-is, without expanding them further to their respective backing indices. -
filteringAliases
public String[] filteringAliases(ClusterState state, String index, Set<IndexNameExpressionResolver.ResolvedExpression> resolvedExpressions) Iterates through the list of indices and selects the effective list of filtering aliases for the given index.Only aliases with filters are returned. If the indices list contains a non-filtering reference to the index itself - null is returned. Returns
nullif no filtering is required. NOTE: The provided expressions must have been resolved already viaresolveExpressionsToResources(Context, String...). -
allIndexAliases
public String[] allIndexAliases(ClusterState state, String index, Set<IndexNameExpressionResolver.ResolvedExpression> resolvedExpressions) Iterates through the list of indices and selects the effective list of all aliases for the given index. Aliases are returned even if the index is included in the resolved expressions. NOTE: The provided expressions must have been resolved already viaresolveExpressions(org.elasticsearch.cluster.ClusterState, java.lang.String...). -
indexAliases
public String[] indexAliases(ClusterState state, String index, Predicate<AliasMetadata> requiredAlias, BiPredicate<DataStreamAlias, Boolean> requiredDataStreamAlias, boolean skipIdentity, Set<IndexNameExpressionResolver.ResolvedExpression> resolvedExpressions) Iterates through the list of indices and selects the effective list of required aliases for the given index.Only aliases where the given predicate tests successfully are returned. If the indices list contains a non-required reference to the index itself - null is returned. Returns
nullif no filtering is required.NOTE: the provided expressions must have been resolved already via
resolveExpressionsToResources(Context, String...). -
resolveSearchRouting
public Map<String,Set<String>> resolveSearchRouting(ClusterState state, @Nullable String routing, String... expressions) Resolves the search routing if in the expression aliases are used. If expressions point to concrete indices or aliases with no routing defined the specified routing is used.- Returns:
- routing values grouped by concrete index
-
resolveSearchRoutingAllIndices
public static Map<String,Set<String>> resolveSearchRoutingAllIndices(Metadata metadata, String routing) Sets the same routing for all indices -
isAllIndicesExpression
public static boolean isAllIndicesExpression(Collection<IndexNameExpressionResolver.ResolvedExpression> aliasesOrIndices) Identifies whether the array containing index names given as argument refers to all indices The empty or null array identifies all indices- Parameters:
aliasesOrIndices- the array containing index names- Returns:
- true if the provided array maps to all indices, false otherwise
-
isAllIndices
Identifies whether the array containing index names given as argument refers to all indices The empty or null array identifies all indices- Parameters:
aliasesOrIndices- the array containing index names- Returns:
- true if the provided array maps to all indices, false otherwise
-
isAllIndices
public static <T> boolean isAllIndices(Collection<T> aliasesOrIndices, Function<T, String> resourceGetter) Identifies whether the array containing objects with index names given as argument refers to all indices The empty or null array identifies all indices- Type Parameters:
T- any object that can contain an index expression in some form or another- Parameters:
aliasesOrIndices- the array containing index namesresourceGetter- allows for obtaining the index name from a generic object that contains an index expression- Returns:
- true if the provided array maps to all indices, false otherwise
-
isNoneExpression
Identifies if this expression list is *,-* which effectively means a request that requests no indices. -
getSystemIndexAccessLevel
- Returns:
- the system access level that will be applied in this resolution. See
SystemIndices.SystemIndexAccessLevelfor details.
-
getSystemIndexAccessPredicate
Determines the right predicate based on thegetSystemIndexAccessLevel(). Specifically: - NONE implies no access to net-new system indices and data streams - BACKWARDS_COMPATIBLE_ONLY allows access also to net-new system resources - ALL allows access to everything - otherwise we fall back toSystemIndices.getProductSystemIndexNamePredicate(ThreadContext)- Returns:
- the predicate that defines the access to system indices.
-
getSystemNameAutomaton
public org.apache.lucene.util.automaton.Automaton getSystemNameAutomaton() -
getNetNewSystemIndexPredicate
-
resolveDateMathExpression
- Returns:
- If the specified string is data math expression then this method returns the resolved expression.
-
resolveDateMathExpression
- Parameters:
time- instant to consider when parsing the expression- Returns:
- If the specified string is data math expression then this method returns the resolved expression.
-