Class ElasticsearchAccess

    • Constructor Summary

      Constructors 
      Constructor Description
      ElasticsearchAccess​(java.lang.String clusterName, java.util.List<ElasticsearchNode> nodes)
      Create an ElasticSearch access
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean checkConnection()
      Check the connection of the database
      void clearScroll​(java.lang.String scrollId)  
      void close()
      Close the ElasticSearch connection
      boolean createIndex​(java.lang.String indexName, java.lang.String mapping)  
      boolean createIndex​(java.lang.String aliasName, java.lang.String indexName, java.lang.String mapping)  
      java.util.Map<java.lang.String,​java.lang.String> createIndexAndAliasIfAliasNotExists​(java.lang.String collectionName, java.lang.String mapping)  
      java.util.Map<java.lang.String,​java.lang.String> createIndexAndAliasIfAliasNotExists​(java.lang.String collectionName, java.lang.String mapping, java.lang.Integer tenantId)  
      java.lang.String createIndexWithoutAlias​(java.lang.String collectionName, java.lang.String mapping, java.lang.Integer tenantId)  
      void delete​(java.lang.String collectionName, java.util.List<java.lang.String> ids, java.lang.Integer tenant)  
      boolean deleteIndex​(java.lang.String indexFullName)  
      void deleteIndexByAlias​(java.lang.String collectionName, java.lang.Integer tenantId)  
      boolean existsAlias​(java.lang.String aliasName)  
      boolean existsIndex​(java.lang.String indexName)  
      org.elasticsearch.client.GetAliasesResponse getAlias​(java.lang.String alias)  
      org.elasticsearch.client.RestHighLevelClient getClient()  
      java.lang.String getClusterName()  
      java.lang.String getInfo()
      Get information on a Database
      java.util.List<ElasticsearchNode> getNodes()  
      void indexEntries​(java.lang.String collectionName, java.lang.Integer tenantId, java.util.Collection<? extends org.bson.Document> documents)
      Add a set of entries in the ElasticSearch index.
      <T extends VitamDocument>
      void
      indexEntry​(java.lang.String collectionName, java.lang.Integer tenantId, java.lang.String id, T vitamDocument)
      Add an entry in the ElasticSearch index
      void purgeIndex​(java.lang.String indexName)  
      void purgeIndex​(java.lang.String collectionName, java.lang.Integer tenant)  
      void refreshIndex​(java.lang.String collectionName, java.lang.Integer tenantId)
      refresh an index
      org.elasticsearch.action.search.SearchResponse search​(java.lang.String collectionName, java.lang.Integer tenantId, org.elasticsearch.index.query.QueryBuilder query)  
      org.elasticsearch.action.search.SearchResponse search​(java.lang.String collectionName, java.lang.Integer tenantId, org.elasticsearch.index.query.QueryBuilder query, org.elasticsearch.index.query.QueryBuilder filter)  
      org.elasticsearch.action.search.SearchResponse search​(java.lang.String collectionName, java.lang.Integer tenantId, org.elasticsearch.index.query.QueryBuilder query, org.elasticsearch.index.query.QueryBuilder filter, java.lang.String[] esProjection, java.util.List<org.elasticsearch.search.sort.SortBuilder> sorts, int offset, java.lang.Integer limit)  
      org.elasticsearch.action.search.SearchResponse search​(java.lang.String collectionName, java.lang.Integer tenantId, org.elasticsearch.index.query.QueryBuilder query, org.elasticsearch.index.query.QueryBuilder filter, java.lang.String[] esProjection, java.util.List<org.elasticsearch.search.sort.SortBuilder> sorts, int offset, java.lang.Integer limit, java.util.List<org.elasticsearch.search.aggregations.AggregationBuilder> facets, java.lang.String scrollId, java.lang.Integer scrollTimeout)  
      boolean switchAliasIndex​(java.lang.String aliasName, java.lang.String oldIndex, java.lang.String newIndexName)  
      void switchIndex​(java.lang.String aliasName, java.lang.String indexNameToSwitchWith)  
      <T extends VitamDocument>
      void
      updateEntry​(java.lang.String collectionName, java.lang.Integer tenantId, java.lang.String id, T vitamDocument)
      Update one element fully
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_SCROLL_TIMEOUT

        public static final int DEFAULT_SCROLL_TIMEOUT
        default limit scroll timeout
        See Also:
        Constant Field Values
      • DEFAULT_LIMIT_SCROLL

        public static final int DEFAULT_LIMIT_SCROLL
        default limit scroll size
        See Also:
        Constant Field Values
      • SCROLL_ACTIVATE_KEYWORD

        public static final java.lang.String SCROLL_ACTIVATE_KEYWORD
        KEYWORD to activate scroll
        See Also:
        Constant Field Values
      • clusterName

        protected final java.lang.String clusterName
    • Constructor Detail

      • ElasticsearchAccess

        public ElasticsearchAccess​(java.lang.String clusterName,
                                   java.util.List<ElasticsearchNode> nodes)
                            throws VitamException,
                                   java.io.IOException
        Create an ElasticSearch access
        Parameters:
        clusterName - the name of the Cluster
        nodes - the elasticsearch nodes
        Throws:
        VitamException - when elasticseach node list is empty
        java.io.IOException
    • Method Detail

      • purgeIndex

        public void purgeIndex​(java.lang.String collectionName,
                               java.lang.Integer tenant)
      • existsIndex

        public boolean existsIndex​(java.lang.String indexName)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • getAlias

        public org.elasticsearch.client.GetAliasesResponse getAlias​(java.lang.String alias)
                                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • createIndex

        public boolean createIndex​(java.lang.String aliasName,
                                   java.lang.String indexName,
                                   java.lang.String mapping)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • createIndex

        public boolean createIndex​(java.lang.String indexName,
                                   java.lang.String mapping)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • existsAlias

        public boolean existsAlias​(java.lang.String aliasName)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • switchAliasIndex

        public boolean switchAliasIndex​(java.lang.String aliasName,
                                        java.lang.String oldIndex,
                                        java.lang.String newIndexName)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • purgeIndex

        public void purgeIndex​(java.lang.String indexName)
      • refreshIndex

        public final void refreshIndex​(java.lang.String collectionName,
                                       java.lang.Integer tenantId)
                                throws java.io.IOException,
                                       DatabaseException
        refresh an index
        Parameters:
        collectionName - the working metadata collection name
        tenantId - the tenant for operation
        Throws:
        java.io.IOException
        DatabaseException
      • indexEntry

        public final <T extends VitamDocument> void indexEntry​(java.lang.String collectionName,
                                                               java.lang.Integer tenantId,
                                                               java.lang.String id,
                                                               T vitamDocument)
                                                        throws DatabaseException
        Add an entry in the ElasticSearch index
        Parameters:
        collectionName -
        tenantId -
        id -
        vitamDocument -
        Throws:
        DatabaseException
      • indexEntries

        public final void indexEntries​(java.lang.String collectionName,
                                       java.lang.Integer tenantId,
                                       java.util.Collection<? extends org.bson.Document> documents)
                                throws DatabaseException
        Add a set of entries in the ElasticSearch index.
        Used in reload from scratch.
        Parameters:
        collectionName - collection of index
        tenantId - tenant Id
        documents - documents to index
        Throws:
        DatabaseException
      • updateEntry

        public <T extends VitamDocument> void updateEntry​(java.lang.String collectionName,
                                                          java.lang.Integer tenantId,
                                                          java.lang.String id,
                                                          T vitamDocument)
                                                   throws DatabaseException
        Update one element fully
        Parameters:
        collectionName -
        tenantId -
        id -
        vitamDocument - full document to update
        Throws:
        DatabaseException
      • search

        public final org.elasticsearch.action.search.SearchResponse search​(java.lang.String collectionName,
                                                                           java.lang.Integer tenantId,
                                                                           org.elasticsearch.index.query.QueryBuilder query,
                                                                           org.elasticsearch.index.query.QueryBuilder filter,
                                                                           java.lang.String[] esProjection,
                                                                           java.util.List<org.elasticsearch.search.sort.SortBuilder> sorts,
                                                                           int offset,
                                                                           java.lang.Integer limit)
                                                                    throws DatabaseException,
                                                                           BadRequestException
        Throws:
        DatabaseException
        BadRequestException
      • search

        public final org.elasticsearch.action.search.SearchResponse search​(java.lang.String collectionName,
                                                                           java.lang.Integer tenantId,
                                                                           org.elasticsearch.index.query.QueryBuilder query,
                                                                           org.elasticsearch.index.query.QueryBuilder filter,
                                                                           java.lang.String[] esProjection,
                                                                           java.util.List<org.elasticsearch.search.sort.SortBuilder> sorts,
                                                                           int offset,
                                                                           java.lang.Integer limit,
                                                                           java.util.List<org.elasticsearch.search.aggregations.AggregationBuilder> facets,
                                                                           java.lang.String scrollId,
                                                                           java.lang.Integer scrollTimeout)
                                                                    throws DatabaseException,
                                                                           BadRequestException
        Throws:
        DatabaseException
        BadRequestException
      • close

        public void close()
        Close the ElasticSearch connection
      • getClusterName

        public java.lang.String getClusterName()
        Returns:
        the Cluster Name
      • getClient

        public org.elasticsearch.client.RestHighLevelClient getClient()
        Returns:
        the client
      • getInfo

        public java.lang.String getInfo()
        Description copied from interface: DatabaseConnection
        Get information on a Database
        Specified by:
        getInfo in interface DatabaseConnection
        Returns:
        information on the database
      • createIndexAndAliasIfAliasNotExists

        public final java.util.Map<java.lang.String,​java.lang.String> createIndexAndAliasIfAliasNotExists​(java.lang.String collectionName,
                                                                                                                java.lang.String mapping)
      • createIndexAndAliasIfAliasNotExists

        public final java.util.Map<java.lang.String,​java.lang.String> createIndexAndAliasIfAliasNotExists​(java.lang.String collectionName,
                                                                                                                java.lang.String mapping,
                                                                                                                java.lang.Integer tenantId)
      • createIndexWithoutAlias

        public final java.lang.String createIndexWithoutAlias​(java.lang.String collectionName,
                                                              java.lang.String mapping,
                                                              java.lang.Integer tenantId)
                                                       throws DatabaseException,
                                                              java.io.IOException
        Throws:
        DatabaseException
        java.io.IOException
      • switchIndex

        public final void switchIndex​(java.lang.String aliasName,
                                      java.lang.String indexNameToSwitchWith)
                               throws DatabaseException,
                                      java.io.IOException
        Throws:
        DatabaseException
        java.io.IOException
      • deleteIndexByAlias

        public final void deleteIndexByAlias​(java.lang.String collectionName,
                                             java.lang.Integer tenantId)
      • deleteIndex

        public final boolean deleteIndex​(java.lang.String indexFullName)
      • delete

        public void delete​(java.lang.String collectionName,
                           java.util.List<java.lang.String> ids,
                           java.lang.Integer tenant)
                    throws DatabaseException
        Throws:
        DatabaseException