Class OpenSearchAdminServiceImpl

java.lang.Object
org.craftercms.search.opensearch.impl.OpenSearchAdminServiceImpl
All Implemented Interfaces:
AutoCloseable, OpenSearchAdminService
Direct Known Subclasses:
MultiOpenSearchAdminServiceImpl

public class OpenSearchAdminServiceImpl extends Object implements OpenSearchAdminService
Default implementation of OpenSearchAdminService
Since:
3.1.0
Author:
joseross
  • Field Details

    • DEFAULT_WAIT_SLEEP_TIME_MILLIS

      public static final int DEFAULT_WAIT_SLEEP_TIME_MILLIS
      See Also:
    • DEFAULT_INDEX_NAME_SUFFIX

      public static final String DEFAULT_INDEX_NAME_SUFFIX
      See Also:
    • ES_STANDARD_ANALYZER

      public static final String ES_STANDARD_ANALYZER
      See Also:
    • ES_KEY_DEFAULT_ANALYZER

      public static final String ES_KEY_DEFAULT_ANALYZER
      See Also:
    • indexNameSuffix

      protected String indexNameSuffix
      The suffix to add to all index names during creation
    • authoringMapping

      protected final org.springframework.core.io.Resource authoringMapping
      Index mapping file for authoring indices
    • previewMapping

      protected final org.springframework.core.io.Resource previewMapping
      Index mapping file for preview indices
    • authoringNamePattern

      protected final String authoringNamePattern
      Regex used to determine if an index is for authoring
    • localeMapping

      protected final Map<String,String> localeMapping
      The map of locale codes to OpenSearch languages
    • openSearchClient

      protected final org.opensearch.client.RestHighLevelClient openSearchClient
      The OpenSearch client
    • defaultSettings

      protected final Map<String,String> defaultSettings
      The default settings used when creating indices
    • ignoredSettings

      protected final Set<String> ignoredSettings
      The settings to ignore on duplicate index
  • Constructor Details

    • OpenSearchAdminServiceImpl

      @ConstructorProperties({"authoringMapping","previewMapping","authoringNamePattern","localeMapping","defaultSettings","ignoredSettings","openSearchClient"}) public OpenSearchAdminServiceImpl(org.springframework.core.io.Resource authoringMapping, org.springframework.core.io.Resource previewMapping, String authoringNamePattern, Map<String,String> localeMapping, Map<String,String> defaultSettings, Set<String> ignoredSettings, org.opensearch.client.RestHighLevelClient openSearchClient)
  • Method Details

    • setIndexNameSuffix

      public void setIndexNameSuffix(String indexNameSuffix)
    • setReindexSlices

      public void setReindexSlices(int reindexSlices)
    • setReindexTimeoutSeconds

      public void setReindexTimeoutSeconds(int reindexTimeoutSeconds)
    • indexExists

      public boolean indexExists(String indexName)
      Description copied from interface: OpenSearchAdminService
      Indicates if an index exists for the given alias
      Specified by:
      indexExists in interface OpenSearchAdminService
      Parameters:
      indexName - the index alias
      Returns:
      true if the index exists, false otherwise
    • doIndexExist

      protected boolean doIndexExist(org.opensearch.client.RestHighLevelClient client, String indexName)
    • createIndex

      public void createIndex(String aliasName) throws OpenSearchException
      Description copied from interface: OpenSearchAdminService
      Creates an index
      Specified by:
      createIndex in interface OpenSearchAdminService
      Parameters:
      aliasName - the name of the alias
      Throws:
      OpenSearchException - if there is any error during the operation
    • createIndex

      public void createIndex(String aliasName, Locale locale) throws OpenSearchException
      Creates an index for the given locale
      Specified by:
      createIndex in interface OpenSearchAdminService
      Parameters:
      aliasName - the name of the alias
      locale - the locale for the index
      Throws:
      OpenSearchException
    • doCreateIndex

      protected void doCreateIndex(org.opensearch.client.RestHighLevelClient client, String aliasName, Locale locale)
      Performs the index creation using the given OpenSearch client
    • doCreateIndex

      protected void doCreateIndex(org.opensearch.client.RestHighLevelClient client, String aliasName, String indexSuffix, Locale locale, boolean createAlias, Map<String,String> settings)
      Performs the index creation using the given OpenSearch client
    • deleteIndexes

      public void deleteIndexes(String aliasName) throws OpenSearchException
      Deletes all indexes assigned to the given alias
      Specified by:
      deleteIndexes in interface OpenSearchAdminService
      Parameters:
      aliasName - the name of the alias
      Throws:
      OpenSearchException - if there is any error during the operation
    • doDeleteIndexes

      protected void doDeleteIndexes(org.opensearch.client.RestHighLevelClient client, String aliasName)
      Performs the index delete using the given OpenSearch client
    • recreateIndex

      public void recreateIndex(String aliasName) throws OpenSearchException
      Recreates an existing index
      Specified by:
      recreateIndex in interface OpenSearchAdminService
      Parameters:
      aliasName - the name of the alias
      Throws:
      OpenSearchException - if there is any error during the operation
    • doRecreateIndex

      protected void doRecreateIndex(org.opensearch.client.RestHighLevelClient client, String aliasName)
      Performs all operations for recreating an index using the given OpenSearch client
    • doGetIndexes

      protected List<String> doGetIndexes(org.opensearch.client.RestHighLevelClient client, String aliasName) throws IOException
      Throws:
      IOException
    • doGetIndexSettings

      protected Map<String,String> doGetIndexSettings(org.opensearch.client.RestHighLevelClient client, String indexAlias) throws IOException
      Throws:
      IOException
    • doReindex

      protected void doReindex(org.opensearch.client.RestHighLevelClient client, String sourceIndex, String destinationIndex) throws IOException
      Throws:
      IOException
    • doSwap

      protected void doSwap(org.opensearch.client.RestHighLevelClient client, String aliasName, String existingIndexName, String newIndexName) throws IOException
      Throws:
      IOException
    • doDeleteIndex

      protected void doDeleteIndex(org.opensearch.client.RestHighLevelClient client, String indexName) throws IOException
      Throws:
      IOException
    • waitUntilReady

      public void waitUntilReady()
      Description copied from interface: OpenSearchAdminService
      Checks if the OpenSearch cluster is ready to receive requests
      Specified by:
      waitUntilReady in interface OpenSearchAdminService
    • duplicateIndex

      public void duplicateIndex(String srcAliasName, String destAliasName) throws OpenSearchException
      Description copied from interface: OpenSearchAdminService
      Create a new index with the same settings and mappings as the source index, then reindex all data to the newly created index.
      Specified by:
      duplicateIndex in interface OpenSearchAdminService
      Parameters:
      srcAliasName - the existing source index
      destAliasName - the new index to be created
      Throws:
      OpenSearchException - if there is any error during the operation
    • doDuplicateIndex

      protected void doDuplicateIndex(org.opensearch.client.RestHighLevelClient client, String srcAliasName, String destAliasName) throws OpenSearchException
      Throws:
      OpenSearchException
    • doWaitUntilReady

      protected void doWaitUntilReady(org.opensearch.client.RestHighLevelClient client)
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception