Class MlIndexAndAlias

java.lang.Object
org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias

public final class MlIndexAndAlias extends Object
Utils to create an ML index with alias ready for rollover with a 6-digit suffix
  • Field Details

    • BWC_MAPPINGS_VERSION

      public static final String BWC_MAPPINGS_VERSION
      ML managed index mappings used to be updated based on the product version. They are now updated based on per-index mappings versions. However, older nodes will still look for a product version in the mappings metadata, so we have to put something in that field that will allow the older node to realise that the mappings are ahead of what it knows about. The easiest solution is to hardcode 8.11.0 in this field, because any node from 8.10.0 onwards should be using per-index mappings versions to determine whether mappings are up-to-date.
      See Also:
    • FIRST_INDEX_SIX_DIGIT_SUFFIX

      public static final String FIRST_INDEX_SIX_DIGIT_SUFFIX
      See Also:
  • Method Details

    • createIndexAndAliasIfNecessary

      public static void createIndexAndAliasIfNecessary(Client client, ClusterState clusterState, IndexNameExpressionResolver resolver, String indexPatternPrefix, String alias, org.elasticsearch.core.TimeValue masterNodeTimeout, ActiveShardCount waitForShardCount, ActionListener<Boolean> finalListener)
      Creates the first index with a name of the given indexPatternPrefix followed by "-000001", if the index is missing. Adds an alias to that index if it was created, or to the index with the highest suffix if the index did not have to be created. The listener is notified with a boolean that informs whether the index or the alias were created. If the index is created, the listener is not called until the index is ready to use via the supplied alias, so that a method that receives a success response from this method can safely use the index immediately.
    • createIndexAndAliasIfNecessary

      public static void createIndexAndAliasIfNecessary(Client client, ClusterState clusterState, IndexNameExpressionResolver resolver, String indexPatternPrefix, String indexNumber, String alias, org.elasticsearch.core.TimeValue masterNodeTimeout, ActiveShardCount waitForShardCount, ActionListener<Boolean> finalListener)
      Same as createIndexAndAliasIfNecessary but with the first concrete index number specified.
    • createSystemIndexIfNecessary

      public static void createSystemIndexIfNecessary(Client client, ClusterState clusterState, SystemIndexDescriptor descriptor, org.elasticsearch.core.TimeValue masterNodeTimeout, ActionListener<Boolean> finalListener)
    • updateWriteAlias

      public static void updateWriteAlias(Client client, String alias, @Nullable String currentIndex, String newIndex, ActionListener<Boolean> listener)
    • installIndexTemplateIfRequired

      public static void installIndexTemplateIfRequired(ClusterState clusterState, Client client, IndexTemplateConfig templateConfig, org.elasticsearch.core.TimeValue masterTimeout, ActionListener<Boolean> listener)
      Installs the index template specified by templateConfig if it is not in already installed in clusterState. The check for presence is simple and will return the listener on the calling thread if successful. If the template has to be installed an async call will be made.
      Parameters:
      clusterState - The cluster state
      client - For putting the template
      templateConfig - The config
      listener - Async listener
    • installIndexTemplateIfRequired

      public static void installIndexTemplateIfRequired(ClusterState clusterState, Client client, int templateVersion, TransportPutComposableIndexTemplateAction.Request templateRequest, ActionListener<Boolean> listener)
      See installIndexTemplateIfRequired(ClusterState, Client, IndexTemplateConfig, TimeValue, ActionListener). Overload takes a PutIndexTemplateRequest instead of IndexTemplateConfig
      Parameters:
      clusterState - The cluster state
      client - For putting the template
      templateRequest - The Put template request
      listener - Async listener
    • hasIndexTemplate

      public static boolean hasIndexTemplate(ClusterState state, String templateName, long version)
    • has6DigitSuffix

      public static boolean has6DigitSuffix(String indexName)
    • latestIndex

      public static String latestIndex(String[] concreteIndices)
      Returns the latest index. Latest is the index with the highest 6 digit suffix.
      Parameters:
      concreteIndices - List of index names
      Returns:
      The latest index by index name version suffix
    • indexIsReadWriteCompatibleInV9

      public static boolean indexIsReadWriteCompatibleInV9(IndexVersion version)
      True if the version is read *and* write compatible not just read only compatible