Class IndexNameExpressionResolver

java.lang.Object
org.elasticsearch.cluster.metadata.IndexNameExpressionResolver

public class IndexNameExpressionResolver extends Object
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.
  • Field Details

    • EXCLUDED_DATA_STREAMS_KEY

      public static final String EXCLUDED_DATA_STREAMS_KEY
      See Also:
    • SYSTEM_INDEX_ENFORCEMENT_INDEX_VERSION

      public static final IndexVersion SYSTEM_INDEX_ENFORCEMENT_INDEX_VERSION
  • Constructor Details

  • Method Details

    • concreteIndexNames

      public String[] concreteIndexNames(ClusterState state, IndicesRequest request)
      Same as concreteIndexNames(ClusterState, IndicesOptions, String...), but the index expressions and options are encapsulated in the specified request.
    • concreteIndexNames

      public String[] concreteIndexNames(ProjectMetadata project, IndicesRequest request)
      Same as concreteIndexNames(ProjectMetadata, IndicesOptions, String...), but the index expressions and options are encapsulated in the specified request.
    • concreteIndexNamesWithSystemIndexAccess

      public String[] concreteIndexNamesWithSystemIndexAccess(ClusterState state, IndicesRequest request)
      Same as concreteIndexNames(ClusterState, IndicesRequest), but access to system indices is always allowed.
    • concreteIndexNamesWithSystemIndexAccess

      public String[] concreteIndexNamesWithSystemIndexAccess(ProjectMetadata project, IndicesRequest request)
      Same as concreteIndexNames(ProjectMetadata, IndicesRequest), but access to system indices is always allowed.
    • concreteIndices

      public Index[] concreteIndices(ClusterState state, IndicesRequest request)
      Same as concreteIndices(ClusterState, IndicesOptions, String...), but the index expressions and options are encapsulated in the specified request and resolves data streams.
    • concreteIndices

      public Index[] concreteIndices(ProjectMetadata projectMetadata, IndicesRequest request)
      Same as concreteIndices(ProjectMetadata, 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 indices
      options - defines how the aliases or indices need to be resolved to concrete indices
      indexExpressions - 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(ProjectMetadata project, IndicesOptions options, String... indexExpressions)
      Translates the provided index expression into actual concrete indices, properly deduplicated.
      Parameters:
      project - the project metadata containing all the data to resolve to expressions to concrete indices
      options - defines how the aliases or indices need to be resolved to concrete indices
      indexExpressions - 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(ProjectMetadata project, IndicesOptions options, boolean includeDataStreams, String... indexExpressions)
    • concreteIndexNames

      public String[] concreteIndexNames(ClusterState state, IndicesOptions options, IndicesRequest request)
    • concreteIndexNames

      public String[] concreteIndexNames(ProjectMetadata project, IndicesOptions options, IndicesRequest request)
    • dataStreamNames

      public List<String> dataStreamNames(ClusterState state, IndicesOptions options, String... indexExpressions)
    • dataStreamNames

      public List<String> dataStreamNames(ProjectMetadata project, IndicesOptions options, String... indexExpressions)
    • dataStreams

      public List<IndexNameExpressionResolver.ResolvedExpression> dataStreams(ClusterState state, IndicesOptions options, String... indexExpressions)
    • dataStreams

      public List<IndexNameExpressionResolver.ResolvedExpression> dataStreams(ProjectMetadata project, IndicesOptions options, String... indexExpressions)
    • resolveWriteIndexAbstraction

      public IndexAbstraction resolveWriteIndexAbstraction(ProjectMetadata project, DocWriteRequest<?> request)
      Returns IndexAbstraction instance for the provided write request. This instance isn't fully resolved, meaning that IndexAbstraction.getWriteIndex() should be invoked in order to get concrete write index.
      Parameters:
      project - The project
      request - The provided write request
      Returns:
      IndexAbstraction instance 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 is true, 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 indices
      options - defines how the aliases or indices need to be resolved to concrete indices
      indexExpressions - 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(ProjectMetadata project, IndicesOptions options, String... indexExpressions)
      Translates the provided index expression into actual concrete indices, properly deduplicated.
      Parameters:
      project - the project containing all the data to resolve to expressions to concrete indices
      options - defines how the aliases or indices need to be resolved to concrete indices
      indexExpressions - 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

      public Index[] concreteIndices(ProjectMetadata project, IndicesOptions options, boolean includeDataStreams, String... indexExpressions)
    • concreteIndices

      public Index[] concreteIndices(ClusterState state, IndicesRequest request, long startTime)
      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 indices
      request - 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.
    • concreteIndices

      public Index[] concreteIndices(ProjectMetadata project, IndicesRequest request, long startTime)
      Translates the provided index expression into actual concrete indices, properly deduplicated.
      Parameters:
      project - the project containing all the data to resolve to expressions to concrete indices
      request - 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

      public Index concreteSingleIndex(ClusterState state, IndicesRequest request)
      Utility method that allows to resolve an index expression to its corresponding single concrete index. Callers should make sure they provide proper IndicesOptions that require a single index as a result. The indices resolution must in fact return a single index when using this method, an IllegalArgumentException gets thrown otherwise.
      Parameters:
      state - the cluster state containing all the data to resolve to expression to a concrete index
      request - 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.
    • concreteSingleIndex

      public Index concreteSingleIndex(ProjectMetadata project, IndicesRequest request)
      Utility method that allows to resolve an index expression to its corresponding single concrete index. Callers should make sure they provide proper IndicesOptions that require a single index as a result. The indices resolution must in fact return a single index when using this method, an IllegalArgumentException gets thrown otherwise.
      Parameters:
      project - the project containing all the data to resolve to expression to a concrete index
      request - 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

      public Index concreteWriteIndex(ProjectMetadata project, IndicesRequest request)
      Utility method that allows to resolve an index expression to its corresponding single write index.
      Parameters:
      project - the project containing all the data to resolve to expression to a concrete index
      request - 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 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 index
      options - defines how the aliases or indices need to be resolved to concrete indices
      index - index that can be resolved to alias or index name.
      allowNoIndices - whether to allow resolve to no index
      includeDataStreams - 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.
    • concreteWriteIndex

      public Index concreteWriteIndex(ProjectMetadata project, IndicesOptions options, String index, boolean allowNoIndices, boolean includeDataStreams)
      Utility method that allows to resolve an index expression to its corresponding single write index.
      Parameters:
      project - the project containing all the data to resolve to expression to a concrete index
      options - defines how the aliases or indices need to be resolved to concrete indices
      index - index that can be resolved to alias or index name.
      allowNoIndices - whether to allow resolve to no index
      includeDataStreams - 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

      public boolean hasIndexAbstraction(String indexAbstraction, ProjectMetadata project)
      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

      public static boolean hasSelectorSuffix(String expression)
      Returns:
      True if the provided expression contains the :: character sequence.
    • hasSelector

      public static boolean hasSelector(@Nullable String expression, IndexComponentSelector selector)
    • splitSelectorExpression

      public static Tuple<String,String> splitSelectorExpression(String expression)
      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

      public static String combineSelectorExpression(String baseExpression, @Nullable String selectorExpression)
    • assertExpressionHasNullOrDataSelector

      public static void assertExpressionHasNullOrDataSelector(String expression)
    • resolveExpressions

      public Set<IndexNameExpressionResolver.ResolvedExpression> resolveExpressions(ProjectMetadata project, String... expressions)
      Resolve an array of expressions to the set of indices and aliases that these expressions match.
    • resolveExpressions

      public Set<IndexNameExpressionResolver.ResolvedExpression> resolveExpressions(ProjectMetadata project, IndicesOptions indicesOptions, boolean preserveDataStreams, String... expressions)
      Resolve the expression to the set of indices, aliases, and, optionally, datastreams that the expression matches. If is true, 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(ProjectMetadata project, 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 null if no filtering is required. NOTE: The provided expressions must have been resolved already via resolveExpressions(org.elasticsearch.cluster.metadata.ProjectMetadata, java.lang.String...).

    • allIndexAliases

      public String[] allIndexAliases(ProjectMetadata project, 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 via resolveExpressions(org.elasticsearch.cluster.metadata.ProjectMetadata, java.lang.String...).
    • indexAliases

      public String[] indexAliases(ProjectMetadata project, 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 null if no filtering is required.

      NOTE: the provided expressions must have been resolved already via resolveExpressions(org.elasticsearch.cluster.metadata.ProjectMetadata, java.lang.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
    • resolveSearchRouting

      public Map<String,Set<String>> resolveSearchRouting(ProjectMetadata project, @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(ProjectMetadata project, 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

      public static boolean isAllIndices(Collection<String> 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

      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 names
      resourceGetter - 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

      public static boolean isNoneExpression(String[] expressions)
      Identifies if this expression list is *,-* which effectively means a request that requests no indices.
    • getSystemIndexAccessLevel

      public SystemIndices.SystemIndexAccessLevel getSystemIndexAccessLevel()
      Returns:
      the system access level that will be applied in this resolution. See SystemIndices.SystemIndexAccessLevel for details.
    • getSystemIndexAccessPredicate

      public Predicate<String> getSystemIndexAccessPredicate()
      Determines the right predicate based on the getSystemIndexAccessLevel(). 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 to SystemIndices.getProductSystemIndexNamePredicate(ThreadContext)
      Returns:
      the predicate that defines the access to system indices.
    • getSystemNameAutomaton

      public org.apache.lucene.util.automaton.Automaton getSystemNameAutomaton()
    • getNetNewSystemIndexPredicate

      public Predicate<String> getNetNewSystemIndexPredicate()
    • resolveDateMathExpression

      public static String resolveDateMathExpression(String dateExpression)
      Returns:
      If the specified string is data math expression then this method returns the resolved expression.
    • resolveDateMathExpression

      public static String resolveDateMathExpression(String dateExpression, long time)
      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.