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
-
-
Field Summary
Fields Modifier and Type Field Description protected ESClient
client
protected ElasticSearchClientConfig
clientConfig
protected ElasticSearchEmbeddedNode
embeddedServer
protected ElasticSearchEmbeddedServerConfig
embeddedServerConfig
protected String[]
excludeSourceFields
protected Map<String,ESHintQueryBuilder>
hints
protected String[]
includeSourceFields
protected Map<String,ElasticSearchIndexConfig>
indexConfig
protected boolean
indexInitDone
protected Map<String,String>
indexNames
protected Map<String,String>
repoNames
protected List<String>
repositoryInitialized
protected static int
TIMEOUT_DELETE_SECOND
protected static int
TIMEOUT_WAIT_FOR_CLUSTER_SECOND
protected AtomicInteger
totalCommandProcessed
protected 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 void
checkClusterHealth(String... indexNames)
protected void
checkConfig()
protected void
connect()
protected ESClient
createClient(ElasticSearchEmbeddedNode node)
void
disconnect()
void
dropAndInitIndex(String indexName)
Reinitialize an index.void
dropAndInitRepositoryIndex(String repositoryName, boolean syncAlias)
Reinitialize the index of a repository.void
flush()
Elasticsearch flush on all document indexes, triggers a lucene commit, empties the transaction log.void
flushRepositoryIndex(String repositoryName)
Elasticsearch flush on document index for a specific repository, triggers a lucene commit, empties the transaction log.ESClient
getClient()
Retrieves theClient
that 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()
String
getIndexNameForRepository(String repositoryName)
Get the search index name associated with the repository name.String
getIndexNameForType(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.long
getPendingWorkerCount()
Returns the number of indexing worker scheduled waiting to be executed.String
getRepositoryForIndex(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.long
getRunningWorkerCount()
Returns the number of indexing worker that are currently running.protected String[]
getSearchIndexes(List<String> searchRepositories)
Get the elastic search indexes for searchesint
getTotalCommandProcessed()
Returns the total number of command processed by Elasticsearch for this Nuxeo instance.String
getWriteIndexName(String searchIndexName)
Returns the index to use for any write operations.protected void
initializeIndexes()
protected void
initIndex(String indexName, ElasticSearchIndexConfig conf, boolean dropIfExists)
protected void
initIndex(ElasticSearchIndexConfig conf, boolean dropIfExists)
protected void
initIndex(ElasticSearchIndexConfig conf, boolean dropIfExists, boolean syncAlias)
void
initIndexes(boolean dropIfExists)
Initialize Elasticsearch indexes.protected void
initSearchAlias(ElasticSearchIndexConfig conf)
protected void
initWriteAlias(ElasticSearchIndexConfig conf, boolean dropIfExists)
boolean
isEmbedded()
Returns true if the Elasticsearch is embedded with Nuxeo, sharing the same JVM.boolean
isIndexingInProgress()
Returns true if there are indexing activities scheduled or running.boolean
isReady()
void
optimize()
Elasticsearch runElasticSearchAdmin.optimizeRepositoryIndex(java.lang.String)
on all document indexes,void
optimizeIndex(String indexName)
Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially be a very heavy operation.void
optimizeRepositoryIndex(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()
AFuture
that accepts callback on completion when all the indexing worker are done.void
refresh()
Refresh all document indexes, immediately after the operation occurs, so that the updated document appears in search results immediately.void
refreshRepositoryIndex(String repositoryName)
Refresh document index for the specific repository, immediately after the operation occurs, so that the updated document appears in search results immediately.void
syncSearchAndWriteAlias(String searchIndexName)
Make sure that the search alias point to the same index as the write alias.protected void
syncSearchAndWriteAlias(ElasticSearchIndexConfig conf)
Update the search index to point to the write index.boolean
useExternalVersion()
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
-
totalCommandProcessed
protected final AtomicInteger totalCommandProcessed
-
indexNames
protected final Map<String,String> indexNames
-
writeIndexNames
protected final Map<String,String> writeIndexNames
-
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
-
indexInitDone
protected boolean indexInitDone
-
includeSourceFields
protected String[] includeSourceFields
-
excludeSourceFields
protected String[] excludeSourceFields
-
repositoryInitialized
protected List<String> repositoryInitialized
-
-
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:ElasticSearchAdmin
Refresh 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:
refreshRepositoryIndex
in interfaceElasticSearchAdmin
-
getIndexNameForRepository
public String getIndexNameForRepository(String repositoryName)
Description copied from interface:ElasticSearchAdmin
Get the search index name associated with the repository name.- Specified by:
getIndexNameForRepository
in interfaceElasticSearchAdmin
-
getRepositoryForIndex
public String getRepositoryForIndex(String indexName)
Description copied from interface:ElasticSearchAdmin
Gets the repository name associated with the index.- Specified by:
getRepositoryForIndex
in interfaceElasticSearchAdmin
-
getIndexNamesForType
public List<String> getIndexNamesForType(String type)
Description copied from interface:ElasticSearchAdmin
Get the index names with the given type.- Specified by:
getIndexNamesForType
in interfaceElasticSearchAdmin
-
getIndexNameForType
public String getIndexNameForType(String type)
Description copied from interface:ElasticSearchAdmin
Get the first search index name with the given type.- Specified by:
getIndexNameForType
in interfaceElasticSearchAdmin
-
getWriteIndexName
public String getWriteIndexName(String searchIndexName)
Description copied from interface:ElasticSearchAdmin
Returns the index to use for any write operations.- Specified by:
getWriteIndexName
in interfaceElasticSearchAdmin
-
syncSearchAndWriteAlias
public void syncSearchAndWriteAlias(String searchIndexName)
Description copied from interface:ElasticSearchAdmin
Make sure that the search alias point to the same index as the write alias.- Specified by:
syncSearchAndWriteAlias
in interfaceElasticSearchAdmin
-
flushRepositoryIndex
public void flushRepositoryIndex(String repositoryName)
Description copied from interface:ElasticSearchAdmin
Elasticsearch flush on document index for a specific repository, triggers a lucene commit, empties the transaction log. Data is flushed to disk.- Specified by:
flushRepositoryIndex
in interfaceElasticSearchAdmin
-
refresh
public void refresh()
Description copied from interface:ElasticSearchAdmin
Refresh 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:
refresh
in interfaceElasticSearchAdmin
-
flush
public void flush()
Description copied from interface:ElasticSearchAdmin
Elasticsearch flush on all document indexes, triggers a lucene commit, empties the transaction log. Data is flushed to disk.- Specified by:
flush
in interfaceElasticSearchAdmin
-
optimizeIndex
public void optimizeIndex(String indexName)
Description copied from interface:ElasticSearchAdmin
Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially be a very heavy operation.- Specified by:
optimizeIndex
in interfaceElasticSearchAdmin
-
optimizeRepositoryIndex
public void optimizeRepositoryIndex(String repositoryName)
Description copied from interface:ElasticSearchAdmin
Elasticsearch optimize operation allows to reduce the number of segments to one, Note that this can potentially be a very heavy operation.- Specified by:
optimizeRepositoryIndex
in interfaceElasticSearchAdmin
-
optimize
public void optimize()
Description copied from interface:ElasticSearchAdmin
Elasticsearch runElasticSearchAdmin.optimizeRepositoryIndex(java.lang.String)
on all document indexes,- Specified by:
optimize
in interfaceElasticSearchAdmin
-
getClient
public ESClient getClient()
Description copied from interface:ElasticSearchAdmin
Retrieves theClient
that can be used to access Elasticsearch API- Specified by:
getClient
in interfaceElasticSearchAdmin
-
initIndexes
public void initIndexes(boolean dropIfExists)
Description copied from interface:ElasticSearchAdmin
Initialize Elasticsearch indexes. Setup the index settings and mapping for each index that has been registered.- Specified by:
initIndexes
in interfaceElasticSearchAdmin
- Parameters:
dropIfExists
- if {true} remove an existing index
-
dropAndInitIndex
public void dropAndInitIndex(String indexName)
Description copied from interface:ElasticSearchAdmin
Reinitialize an index. This will drop the existing index, recreate it with its settings and mapping, the index will be empty.- Specified by:
dropAndInitIndex
in interfaceElasticSearchAdmin
-
dropAndInitRepositoryIndex
public void dropAndInitRepositoryIndex(String repositoryName, boolean syncAlias)
Description copied from interface:ElasticSearchAdmin
Reinitialize 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:
dropAndInitRepositoryIndex
in interfaceElasticSearchAdmin
-
getRepositoryNames
public List<String> getRepositoryNames()
Description copied from interface:ElasticSearchAdmin
List repository names that have Elasticsearch support.- Specified by:
getRepositoryNames
in 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 dropIfExists)
-
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:ElasticSearchAdmin
Returns the number of indexing worker scheduled waiting to be executed.- Specified by:
getPendingWorkerCount
in interfaceElasticSearchAdmin
-
getRunningWorkerCount
public long getRunningWorkerCount()
Description copied from interface:ElasticSearchAdmin
Returns the number of indexing worker that are currently running.- Specified by:
getRunningWorkerCount
in interfaceElasticSearchAdmin
-
getTotalCommandProcessed
public int getTotalCommandProcessed()
Description copied from interface:ElasticSearchAdmin
Returns the total number of command processed by Elasticsearch for this Nuxeo instance. Useful for test assertion.- Specified by:
getTotalCommandProcessed
in interfaceElasticSearchAdmin
-
isEmbedded
public boolean isEmbedded()
Description copied from interface:ElasticSearchAdmin
Returns true if the Elasticsearch is embedded with Nuxeo, sharing the same JVM.- Specified by:
isEmbedded
in interfaceElasticSearchAdmin
-
useExternalVersion
public boolean useExternalVersion()
Description copied from interface:ElasticSearchAdmin
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.- Specified by:
useExternalVersion
in interfaceElasticSearchAdmin
-
isIndexingInProgress
public boolean isIndexingInProgress()
Description copied from interface:ElasticSearchAdmin
Returns true if there are indexing activities scheduled or running.- Specified by:
isIndexingInProgress
in interfaceElasticSearchAdmin
-
prepareWaitForIndexing
public com.google.common.util.concurrent.ListenableFuture<Boolean> prepareWaitForIndexing()
Description copied from interface:ElasticSearchAdmin
AFuture
that accepts callback on completion when all the indexing worker are done.- Specified by:
prepareWaitForIndexing
in 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()
-
getRepositoryMap
protected Map<String,String> getRepositoryMap()
-
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:ElasticSearchAdmin
Returns the hint by the Elasticsearch operator name.- Specified by:
getHintByOperator
in interfaceElasticSearchAdmin
-
-