Class IndexNameExpressionResolver

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

@PublicApi(since="1.0.0") public class IndexNameExpressionResolver extends Object
Resolves index name from an expression
Opensearch.api:
  • Field Details

    • EXCLUDED_DATA_STREAMS_KEY

      public static final String EXCLUDED_DATA_STREAMS_KEY
      See Also:
    • SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY

      public static final String SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY
      See Also:
    • SYSTEM_INDEX_ENFORCEMENT_VERSION

      public static final org.opensearch.Version SYSTEM_INDEX_ENFORCEMENT_VERSION
  • Constructor Details

    • IndexNameExpressionResolver

      public IndexNameExpressionResolver(ThreadContext threadContext)
  • 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.
    • concreteIndexNamesWithSystemIndexAccess

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

      public org.opensearch.core.index.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.
    • 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.
    • 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)
    • concreteIndices

      public org.opensearch.core.index.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.
    • concreteIndices

      public org.opensearch.core.index.Index[] concreteIndices(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions)
    • concreteIndices

      public org.opensearch.core.index.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.
    • concreteSingleIndex

      public org.opensearch.core.index.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 lead to more than one index
    • concreteWriteIndex

      public org.opensearch.core.index.Index concreteWriteIndex(ClusterState state, IndicesRequest request)
      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
      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 org.opensearch.core.index.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
    • hasIndexAbstraction

      public boolean hasIndexAbstraction(String indexAbstraction, ClusterState state)
      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.
    • resolveDateMathExpression

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

      public Set<String> resolveExpressions(ClusterState state, String... expressions)
      Resolve an array of expressions to the set of indices and aliases that these expressions match.
    • filteringAliases

      public String[] filteringAliases(ClusterState state, String index, Set<String> 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.opensearch.cluster.ClusterState, java.lang.String...).

    • indexAliases

      public String[] indexAliases(ClusterState state, String index, Predicate<AliasMetadata> requiredAlias, boolean skipIdentity, Set<String> 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.opensearch.cluster.ClusterState, 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
    • resolveSearchRoutingAllIndices

      public Map<String,Set<String>> resolveSearchRoutingAllIndices(Metadata metadata, String routing)
      Sets the same routing for all indices
    • 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
    • isSystemIndexAccessAllowed

      public boolean isSystemIndexAccessAllowed()
      Determines whether or not system index access should be allowed in the current context.
      Returns:
      True if system index access should be allowed, false otherwise.