Package org.nuxeo.elasticsearch.core
Class ElasticSearchAdminImpl
- java.lang.Object
-
- org.nuxeo.elasticsearch.core.ElasticSearchAdminImpl
-
- All Implemented Interfaces:
ElasticSearchAdmin
public class ElasticSearchAdminImpl extends Object implements ElasticSearchAdmin
- Since:
- 6.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classElasticSearchAdminImpl.ReindexingPubSub
-
Field Summary
Fields Modifier and Type Field Description protected ESClientclientprotected ElasticSearchClientConfigclientConfigprotected ElasticSearchEmbeddedNodeembeddedServerprotected ElasticSearchEmbeddedServerConfigembeddedServerConfigstatic StringES_KV_STOREprotected String[]excludeSourceFieldsprotected Map<String,ESHintQueryBuilder>hintsprotected String[]includeSourceFieldsprotected Map<String,ElasticSearchIndexConfig>indexConfigprotected booleanindexInitDoneprotected Map<String,String>indexNamesstatic StringREINDEXING_PUBSUB_TOPICprotected ElasticSearchAdminImpl.ReindexingPubSubreindexingPubSubprotected Map<String,String>repoNamesprotected List<String>repositoryInitializedprotected Map<String,String>secondaryWriteIndexNamesprotected static intTIMEOUT_DELETE_SECONDprotected static intTIMEOUT_WAIT_FOR_CLUSTER_SECONDprotected AtomicIntegertotalCommandProcessedprotected booleanuseSecondaryWriteIndexprotected Map<String,String>writeIndexNames
-
Constructor Summary
Constructors Constructor Description ElasticSearchAdminImpl(ElasticSearchEmbeddedServerConfig embeddedServerConfig, ElasticSearchClientConfig clientConfig, Map<String,ElasticSearchIndexConfig> indexConfig, Collection<ESHintQueryBuilderDescriptor> hintDescriptors)Init the admin service, remote configuration if not null will take precedence over local embedded configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckClusterHealth(String... indexNames)protected voidcheckConfig()protected voidconnect()protected ESClientcreateClient(ElasticSearchEmbeddedNode node)voiddisconnect()voiddropAndInitIndex(String indexName)Reinitialize an index.voiddropAndInitRepositoryIndex(String repositoryName, boolean syncAlias)Reinitialize the index of a repository.voidflush()Elasticsearch flush on all document indexes, triggers a lucene commit, empties the transaction log.voidflushRepositoryIndex(String repositoryName)Elasticsearch flush on document index for a specific repository, triggers a lucene commit, empties the transaction log.ESClientgetClient()Retrieves theClientthat can be used to access Elasticsearch APIprotected String[]getExcludeSourceFields()Optional<ESHintQueryBuilder>getHintByOperator(String name)Returns the hint by the Elasticsearch operator name.protected String[]getIncludeSourceFields()StringgetIndexNameForRepository(String repositoryName)Get the search index name associated with the repository name.StringgetIndexNameForType(String type)Get the first search index name with the given type.List<String>getIndexNamesForType(String type)Get the index names with the given type.List<String>getInitializedRepositories()Get the list of repository names that have their index created.protected KeyValueStoregetKvStore()longgetPendingWorkerCount()Returns the number of indexing worker scheduled waiting to be executed.StringgetRepositoryForIndex(String indexName)Gets the repository name associated with the index.protected Map<String,String>getRepositoryMap()List<String>getRepositoryNames()List repository names that have Elasticsearch support.longgetRunningWorkerCount()Returns the number of indexing worker that are currently running.protected String[]getSearchIndexes(List<String> searchRepositories)Get the elastic search indexes for searchesStringgetSecondaryWriteIndexName(String searchIndexName)Returns the secondary write index used during re-indexing with aliases.intgetTotalCommandProcessed()Returns the total number of command processed by Elasticsearch for this Nuxeo instance.StringgetWriteIndexName(String searchIndexName)Returns the index to use for any write operations.protected voidinitializeIndexes()protected voidinitIndex(String indexName, ElasticSearchIndexConfig conf, boolean dropIfExists)protected voidinitIndex(ElasticSearchIndexConfig conf, boolean dropIfExists)protected voidinitIndex(ElasticSearchIndexConfig conf, boolean dropIfExists, boolean syncAlias)voidinitIndexes(boolean dropIfExists)Initialize Elasticsearch indexes.voidinitRepositoryIndexWithAliases(String repositoryName)Creates a new index for the repository applying the mapping and settings.protected voidinitSearchAlias(ElasticSearchIndexConfig conf)protected voidinitWriteAlias(ElasticSearchIndexConfig conf, boolean create)booleanisEmbedded()Returns true if the Elasticsearch is embedded with Nuxeo, sharing the same JVM.booleanisIndexingInProgress()Returns true if there are indexing activities scheduled or running.booleanisReady()voidoptimize()Elasticsearch runElasticSearchAdmin.optimizeRepositoryIndex(java.lang.String)on all document indexes,voidoptimizeIndex(String indexName)Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially be a very heavy operation.voidoptimizeRepositoryIndex(String repositoryName)Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially be a very heavy operation.com.google.common.util.concurrent.ListenableFuture<Boolean>prepareWaitForIndexing()AFuturethat accepts callback on completion when all the indexing worker are done.voidrefresh()Refresh all document indexes, immediately after the operation occurs, so that the updated document appears in search results immediately.voidrefreshRepositoryIndex(String repositoryName)Refresh document index for the specific repository, immediately after the operation occurs, so that the updated document appears in search results immediately.voidsyncSearchAndWriteAlias(String searchIndexName)Make sure that the search alias point to the same index as the write alias.protected voidsyncSearchAndWriteAlias(ElasticSearchIndexConfig conf)Update the search index to point to the write index.booleanuseExternalVersion()When true use an external version for Elasticsearch document, this enable an optimistic concurrency control ensuring that an older version of a document never overwrites a newer version.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.elasticsearch.api.ElasticSearchAdmin
dropAndInitRepositoryIndex
-
-
-
-
Field Detail
-
TIMEOUT_WAIT_FOR_CLUSTER_SECOND
protected static final int TIMEOUT_WAIT_FOR_CLUSTER_SECOND
- See Also:
- Constant Field Values
-
TIMEOUT_DELETE_SECOND
protected static final int TIMEOUT_DELETE_SECOND
- See Also:
- Constant Field Values
-
ES_KV_STORE
public static final String ES_KV_STORE
- See Also:
- Constant Field Values
-
totalCommandProcessed
protected final AtomicInteger totalCommandProcessed
-
useSecondaryWriteIndex
protected boolean useSecondaryWriteIndex
-
reindexingPubSub
protected final ElasticSearchAdminImpl.ReindexingPubSub reindexingPubSub
-
REINDEXING_PUBSUB_TOPIC
public static final String REINDEXING_PUBSUB_TOPIC
- See Also:
- Constant Field Values
-
indexConfig
protected final Map<String,ElasticSearchIndexConfig> indexConfig
-
hints
protected Map<String,ESHintQueryBuilder> hints
-
embeddedServerConfig
protected final ElasticSearchEmbeddedServerConfig embeddedServerConfig
-
clientConfig
protected final ElasticSearchClientConfig clientConfig
-
embeddedServer
protected ElasticSearchEmbeddedNode embeddedServer
-
client
protected ESClient client
-
indexInitDone
protected boolean indexInitDone
-
includeSourceFields
protected String[] includeSourceFields
-
excludeSourceFields
protected String[] excludeSourceFields
-
-
Constructor Detail
-
ElasticSearchAdminImpl
public ElasticSearchAdminImpl(ElasticSearchEmbeddedServerConfig embeddedServerConfig, ElasticSearchClientConfig clientConfig, Map<String,ElasticSearchIndexConfig> indexConfig, Collection<ESHintQueryBuilderDescriptor> hintDescriptors)
Init the admin service, remote configuration if not null will take precedence over local embedded configuration. The transport client initialization can be customized.- Since:
- 9.1
-
-
Method Detail
-
checkConfig
protected void checkConfig()
-
connect
protected void connect()
-
disconnect
public void disconnect()
-
createClient
protected ESClient createClient(ElasticSearchEmbeddedNode node)
-
checkClusterHealth
protected void checkClusterHealth(String... indexNames)
-
initializeIndexes
protected void initializeIndexes()
-
refreshRepositoryIndex
public void refreshRepositoryIndex(String repositoryName)
Description copied from interface:ElasticSearchAdminRefresh document index for the specific repository, immediately after the operation occurs, so that the updated document appears in search results immediately. There is no fsync thus doesn't guarantee durability.- Specified by:
refreshRepositoryIndexin interfaceElasticSearchAdmin
-
getIndexNameForRepository
public String getIndexNameForRepository(String repositoryName)
Description copied from interface:ElasticSearchAdminGet the search index name associated with the repository name.- Specified by:
getIndexNameForRepositoryin interfaceElasticSearchAdmin
-
getRepositoryForIndex
public String getRepositoryForIndex(String indexName)
Description copied from interface:ElasticSearchAdminGets the repository name associated with the index.- Specified by:
getRepositoryForIndexin interfaceElasticSearchAdmin
-
getIndexNamesForType
public List<String> getIndexNamesForType(String type)
Description copied from interface:ElasticSearchAdminGet the index names with the given type.- Specified by:
getIndexNamesForTypein interfaceElasticSearchAdmin
-
getIndexNameForType
public String getIndexNameForType(String type)
Description copied from interface:ElasticSearchAdminGet the first search index name with the given type.- Specified by:
getIndexNameForTypein interfaceElasticSearchAdmin
-
getWriteIndexName
public String getWriteIndexName(String searchIndexName)
Description copied from interface:ElasticSearchAdminReturns the index to use for any write operations.- Specified by:
getWriteIndexNamein interfaceElasticSearchAdmin
-
getSecondaryWriteIndexName
public String getSecondaryWriteIndexName(String searchIndexName)
Description copied from interface:ElasticSearchAdminReturns the secondary write index used during re-indexing with aliases.- Specified by:
getSecondaryWriteIndexNamein interfaceElasticSearchAdmin- Returns:
- an index name or null if there is no re-indexing in progress.
-
syncSearchAndWriteAlias
public void syncSearchAndWriteAlias(String searchIndexName)
Description copied from interface:ElasticSearchAdminMake sure that the search alias point to the same index as the write alias.- Specified by:
syncSearchAndWriteAliasin interfaceElasticSearchAdmin
-
flushRepositoryIndex
public void flushRepositoryIndex(String repositoryName)
Description copied from interface:ElasticSearchAdminElasticsearch flush on document index for a specific repository, triggers a lucene commit, empties the transaction log. Data is flushed to disk.- Specified by:
flushRepositoryIndexin interfaceElasticSearchAdmin
-
refresh
public void refresh()
Description copied from interface:ElasticSearchAdminRefresh all document indexes, immediately after the operation occurs, so that the updated document appears in search results immediately. There is no fsync thus doesn't guarantee durability.- Specified by:
refreshin interfaceElasticSearchAdmin
-
flush
public void flush()
Description copied from interface:ElasticSearchAdminElasticsearch flush on all document indexes, triggers a lucene commit, empties the transaction log. Data is flushed to disk.- Specified by:
flushin interfaceElasticSearchAdmin
-
optimizeIndex
public void optimizeIndex(String indexName)
Description copied from interface:ElasticSearchAdminElasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially be a very heavy operation.- Specified by:
optimizeIndexin interfaceElasticSearchAdmin
-
optimizeRepositoryIndex
public void optimizeRepositoryIndex(String repositoryName)
Description copied from interface:ElasticSearchAdminElasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially be a very heavy operation.- Specified by:
optimizeRepositoryIndexin interfaceElasticSearchAdmin
-
optimize
public void optimize()
Description copied from interface:ElasticSearchAdminElasticsearch runElasticSearchAdmin.optimizeRepositoryIndex(java.lang.String)on all document indexes,- Specified by:
optimizein interfaceElasticSearchAdmin
-
getClient
public ESClient getClient()
Description copied from interface:ElasticSearchAdminRetrieves theClientthat can be used to access Elasticsearch API- Specified by:
getClientin interfaceElasticSearchAdmin
-
initIndexes
public void initIndexes(boolean dropIfExists)
Description copied from interface:ElasticSearchAdminInitialize Elasticsearch indexes. Setup the index settings and mapping for each index that has been registered.- Specified by:
initIndexesin interfaceElasticSearchAdmin- Parameters:
dropIfExists- if {true} remove an existing index
-
dropAndInitIndex
public void dropAndInitIndex(String indexName)
Description copied from interface:ElasticSearchAdminReinitialize an index. This will drop the existing index, recreate it with its settings and mapping, the index will be empty.- Specified by:
dropAndInitIndexin interfaceElasticSearchAdmin
-
dropAndInitRepositoryIndex
public void dropAndInitRepositoryIndex(String repositoryName, boolean syncAlias)
Description copied from interface:ElasticSearchAdminReinitialize the index of a repository. This will drop the existing index, recreate it with its settings and mapping, the index will be empty. When syncAlias is false then search alias is not updated with the new index, you need to explicitly callElasticSearchAdmin.syncSearchAndWriteAlias(String)- Specified by:
dropAndInitRepositoryIndexin interfaceElasticSearchAdmin
-
initRepositoryIndexWithAliases
public void initRepositoryIndexWithAliases(String repositoryName)
Description copied from interface:ElasticSearchAdminCreates a new index for the repository applying the mapping and settings. Update the write alias to point to this new index. The search alias is updated to the new index only for the initial creation. Otherwise, there are two write indexes until an explicit call toElasticSearchAdmin.syncSearchAndWriteAlias(String).- Specified by:
initRepositoryIndexWithAliasesin interfaceElasticSearchAdmin
-
getRepositoryNames
public List<String> getRepositoryNames()
Description copied from interface:ElasticSearchAdminList repository names that have Elasticsearch support.- Specified by:
getRepositoryNamesin interfaceElasticSearchAdmin
-
initIndex
protected void initIndex(ElasticSearchIndexConfig conf, boolean dropIfExists)
-
initIndex
protected void initIndex(ElasticSearchIndexConfig conf, boolean dropIfExists, boolean syncAlias)
-
initWriteAlias
protected void initWriteAlias(ElasticSearchIndexConfig conf, boolean create)
-
initSearchAlias
protected void initSearchAlias(ElasticSearchIndexConfig conf)
-
syncSearchAndWriteAlias
protected void syncSearchAndWriteAlias(ElasticSearchIndexConfig conf)
Update the search index to point to the write index.
-
initIndex
protected void initIndex(String indexName, ElasticSearchIndexConfig conf, boolean dropIfExists)
-
getPendingWorkerCount
public long getPendingWorkerCount()
Description copied from interface:ElasticSearchAdminReturns the number of indexing worker scheduled waiting to be executed.- Specified by:
getPendingWorkerCountin interfaceElasticSearchAdmin
-
getRunningWorkerCount
public long getRunningWorkerCount()
Description copied from interface:ElasticSearchAdminReturns the number of indexing worker that are currently running.- Specified by:
getRunningWorkerCountin interfaceElasticSearchAdmin
-
getTotalCommandProcessed
public int getTotalCommandProcessed()
Description copied from interface:ElasticSearchAdminReturns the total number of command processed by Elasticsearch for this Nuxeo instance. Useful for test assertion.- Specified by:
getTotalCommandProcessedin interfaceElasticSearchAdmin
-
isEmbedded
public boolean isEmbedded()
Description copied from interface:ElasticSearchAdminReturns true if the Elasticsearch is embedded with Nuxeo, sharing the same JVM.- Specified by:
isEmbeddedin interfaceElasticSearchAdmin
-
useExternalVersion
public boolean useExternalVersion()
Description copied from interface:ElasticSearchAdminWhen true use an external version for Elasticsearch document, this enable an optimistic concurrency control ensuring that an older version of a document never overwrites a newer version.- Specified by:
useExternalVersionin interfaceElasticSearchAdmin
-
isIndexingInProgress
public boolean isIndexingInProgress()
Description copied from interface:ElasticSearchAdminReturns true if there are indexing activities scheduled or running.- Specified by:
isIndexingInProgressin interfaceElasticSearchAdmin
-
prepareWaitForIndexing
public com.google.common.util.concurrent.ListenableFuture<Boolean> prepareWaitForIndexing()
Description copied from interface:ElasticSearchAdminAFuturethat accepts callback on completion when all the indexing worker are done.- Specified by:
prepareWaitForIndexingin interfaceElasticSearchAdmin
-
getSearchIndexes
protected String[] getSearchIndexes(List<String> searchRepositories)
Get the elastic search indexes for searches
-
isReady
public boolean isReady()
-
getIncludeSourceFields
protected String[] getIncludeSourceFields()
-
getExcludeSourceFields
protected String[] getExcludeSourceFields()
-
getInitializedRepositories
public List<String> getInitializedRepositories()
Get the list of repository names that have their index created.
-
getHintByOperator
public Optional<ESHintQueryBuilder> getHintByOperator(String name)
Description copied from interface:ElasticSearchAdminReturns the hint by the Elasticsearch operator name.- Specified by:
getHintByOperatorin interfaceElasticSearchAdmin
-
getKvStore
protected KeyValueStore getKvStore()
-
-