Class ElasticsearchRepository

    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addDocument​(Document document)
      Adds a document to the index.
      void addDocumentToIndexQueue​(Document document)
      Adds a document that may be delayed until it is indexed.
      void addIndex​(java.util.Locale locale)
      Adds the indices relative to the given locale in Elasticsearch.
      void addOrUpdateDocument​(Document document)
      Adds or updates a document on the index.
      void addOrUpdateDocumentType​(DocumentType documentType)
      Deprecated.
      void addOrUpdateDocumentType​(DocumentType documentType, boolean force)
      Adds or updates a document type into managed indices.
      If the managed indices couldn't be updated in underlying big data repository:
      If force parameter is true, they will be recreated, causing data loss. Else, an IllegalArgumentException will be raised.
      co.elastic.clients.elasticsearch.core.SearchRequest.Builder createSearchRequestBuilder​(SearchQuery searchQuery)
      Returns a new Elasticsearch search request builder for the given SearchQuery.
      void deleteDocument​(DocumentType documentType, java.util.Locale locale, java.lang.String documentId)
      Deletes a document from the index with the given specifications.
      void deleteDocumentsByFieldValue​(java.lang.String fieldId, java.lang.Object... values)
      Deletes documents that are matched by one of the given values in the field of given field identifier.
      void deleteDocumentsByFieldValue​(java.lang.String fieldId, java.util.Collection<?> values)
      Deletes documents that are matched by one of the given values in the field of given field identifier.
      void deleteDocumentsByQuery​(SearchQuery searchQuery)
      Deletes documents that are matched by the given search query.
      The search query's sorts, initial hit and maximum hit count will be ignored.
      void deleteDocumentType​(java.lang.String documentTypeId)
      Deletes a given document type from managed indices.
      void deleteIndex​(java.util.Locale locale)
      Deletes the indices related to the given locale.
      void deleteLegacyIndicesTemplates()
      Delete the all legacy index templates.
      void destroy()
      Destroy this repository and performs any required resource freeing.
      protected <R extends org.elasticsearch.action.DocWriteRequest<R>>
      void
      executeAsync​(R request)
      Deprecated.
      Since 16.1.0 due to deprecation of RestHighLevelClient.
      protected <R extends org.elasticsearch.action.DocWriteRequest<R>>
      void
      executeAsync​(R request, boolean doFlush)
      Deprecated.
      Since 16.1.0 due to deprecation of RestHighLevelClient.
      protected co.elastic.clients.elasticsearch.core.SearchResponse<java.util.Map<java.lang.String,​java.lang.Object>> executeSync​(co.elastic.clients.elasticsearch.core.SearchRequest query)
      Executes the given query and return the response.
      protected <REQ,​RESP>
      RESP
      executeSync​(REQ request, java.util.function.Function<org.elasticsearch.client.RestHighLevelClient,​lumis.portal.bigdata.elasticsearch.ElasticsearchIndexer.IResponseSupplier<REQ,​RESP>> supplierCreator)
      Deprecated.
      Since 16.1.0 due to deprecation of RestHighLevelClient.
      protected <REQ,​RESP>
      RESP
      executeSync​(REQ request, lumis.portal.bigdata.elasticsearch.ElasticsearchIndexer.IResponseSupplier<REQ,​RESP> supplier)
      Deprecated.
      Since 16.1.0 due to deprecation of RestHighLevelClient.
      java.util.Collection<java.lang.String> findDocumentTypesMissingIndices()
      Returns the missing indices that are supposed to exist due to existent document types.
      java.util.Map<java.lang.String,​? extends DocumentType> getAllDocumentTypes()
      Returns all document types, indexed by document type identifier.
      java.lang.String[] getAllIndicesNames​(DocumentType type)
      Return all portal indices names for a type - for each locale - include null - generate a index name.
      java.util.List<java.lang.String> getAutoCompleteSuggestions​(SearchQuery searchQuery, AutoCompleteSuggestionConfig autoCompleteSuggestion)
      Returns a list of auto complete suggestions for the given auto complete suggestion configuration and the search query.
      protected co.elastic.clients.elasticsearch.core.SearchRequest.Builder getBaseQuery​(SearchQuery searchQuery)
      Returns a search request builder based on the given SearchQuery.
      BulkProcessor getBulkProcessor()
      Returns an internal bulk processor used by this repository.
      org.elasticsearch.client.RestHighLevelClient getDelegate()
      Deprecated.
      Since 16.1.0 replaced by getDelegate(Class).
      <T> T getDelegate​(java.lang.Class<T> type)
      Returns the underlying Elasticsearch client of this repository.
      DocumentType getDocumentType​(java.lang.String documentTypeId)
      Returns the document type of the given identifier.
      DocumentType getDocumentTypeByIndex​(java.lang.String index)
      Return the DocumentType for index name.
      DocumentTypeField getDocumentTypeField​(java.lang.String documentTypeFieldFullId)
      Return the document type field of the field that has the given identifier.
      java.lang.String getIndexTemplateSettings​(java.util.Locale locale)
      Returns the index template settings for the given locale.
      java.util.List<java.lang.String> getIndices​(SearchQuery searchQuery)
      Returns the indices to be used for a search query.
      co.elastic.clients.elasticsearch._types.query_dsl.Query getQuery​(SearchQuery searchQuery)
      Generates a Elasticsearch's Query generated according to a given LumisXP's SearchQuery.
      org.elasticsearch.client.RequestOptions getRequestOptions()
      Returns the default request options.
      java.lang.String getRetiredAliasName()
      Returns the alias used for LumisXP indices that were used in previous versions but are no longer used in current version.
      java.lang.String getSearchAliasName()
      Returns the alias used for searching in LumisXP indices.
      java.util.Map<java.util.Locale,​IFile> getSynonymsFiles()
      Return a map with all files that the portal need to create based the Locales of synonyms and Locales of portal.
      void init​(java.lang.String repositoryId)
      Initializes this repository using the given node as configuration.
      Document readDocument​(DocumentType documentType, java.util.Locale locale, java.lang.String documentId)
      Reads a document from the repository with the given specifications.
      void refreshIndices​(java.lang.String documentTypeId, java.util.Locale... locales)
      Refresh the indices of the given document type.
      void refreshIndices​(java.util.Collection<java.lang.String> documentTypeIds, java.util.Locale... locales)
      Refresh the indices of the given document type.
      void refreshIndices​(DocumentType documentType, java.util.Locale... locales)
      Refresh the indices of the given document type.
      void reloadSynonyms()
      Reloads the synonyms in this repository.
      ISearchResults search​(SearchQuery searchQuery)
      Runs the given search query and returns the search results.
      <T> java.util.List<T> searchUsingScroll​(co.elastic.clients.elasticsearch.core.SearchRequest.Builder query, int startAt, int maxResults, java.util.function.Function<co.elastic.clients.elasticsearch.core.search.ResponseBody<java.util.Map<java.lang.String,​java.lang.Object>>,​java.util.List<T>> collector)
      Performs the searching using scroll and collect data from all ranges.
      IBatchIndexer startBatch()
      Returns an indexer to perform bulk actions.
      The caller must assure IBatchIndexer.close() is called after the desired bulk operations were performed.
      void updateDocumentsByQuerySync​(SearchQuery searchQuery, java.util.Map<java.lang.String,​java.lang.Object> fieldValues)
      Updates documents that matches a SearchQuery updating their field values according to the fieldValues map.
      void validate​(SearchQuery searchQuery)
      Checks is the given search query is syntactically correct.
      • Methods inherited from class java.lang.Object

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

      • NATIVE_TEMPLATES_SYNONYMS_LOCALES

        public static final java.util.List<java.util.Locale> NATIVE_TEMPLATES_SYNONYMS_LOCALES
      • client

        @Deprecated
        protected org.elasticsearch.client.RestHighLevelClient client
        Deprecated.
        Old Elasticsearch client, replaced by esClient.
      • esClient

        protected co.elastic.clients.elasticsearch.ElasticsearchClient esClient
        Elasticsearch client (new client introduced with Elasticsearch 8).
        Since:
        16.1.0
      • requestOptions

        protected org.elasticsearch.client.RequestOptions requestOptions
    • Constructor Detail

      • ElasticsearchRepository

        public ElasticsearchRepository()
    • Method Detail

      • init

        public void init​(java.lang.String repositoryId)
        Description copied from interface: IBigDataRepositorySPI
        Initializes this repository using the given node as configuration.
        Specified by:
        init in interface IBigDataRepositorySPI
        Parameters:
        repositoryId - the repository identifier.
      • deleteLegacyIndicesTemplates

        public void deleteLegacyIndicesTemplates()
        Delete the all legacy index templates.
        Since:
        14.2.0
      • getSearchAliasName

        public java.lang.String getSearchAliasName()
        Returns the alias used for searching in LumisXP indices.
        Returns:
        the alias.
        Since:
        8.2.1
      • getRetiredAliasName

        public java.lang.String getRetiredAliasName()
        Returns the alias used for LumisXP indices that were used in previous versions but are no longer used in current version.

        This method is intended for use by special upgrade tasks so they can find the indices with previous versions data so they can convert them to current format.

        Returns:
        the alias.
        Since:
        11.0.0
      • addIndex

        public void addIndex​(java.util.Locale locale)
        Adds the indices relative to the given locale in Elasticsearch.
        Parameters:
        locale - the locale the indices to be created refers to.
        Since:
        8.1.0
      • deleteIndex

        public void deleteIndex​(java.util.Locale locale)
        Deletes the indices related to the given locale.
        Parameters:
        locale - the locale.
        Since:
        8.1.0
      • getIndexTemplateSettings

        public java.lang.String getIndexTemplateSettings​(java.util.Locale locale)
        Returns the index template settings for the given locale.
        Parameters:
        locale - the locale or null for locale agnostic settings.
        Returns:
        the index template settings for the given locale.
        Since:
        8.2.1
      • addOrUpdateDocumentType

        @Deprecated
        public void addOrUpdateDocumentType​(DocumentType documentType)
        Deprecated.
        Description copied from interface: IBigDataRepository
        Adds or updates a document type into managed indices.
        If the managed indices couldn't be updated in underlying big data repository, they will be recreated, causing data loss.
        Specified by:
        addOrUpdateDocumentType in interface IBigDataRepository
        Parameters:
        documentType - the document type to be added.
        See Also:
        DocumentTypes
      • addOrUpdateDocumentType

        public void addOrUpdateDocumentType​(DocumentType documentType,
                                            boolean force)
        Description copied from interface: IBigDataRepository
        Adds or updates a document type into managed indices.
        If the managed indices couldn't be updated in underlying big data repository:
        • If force parameter is true, they will be recreated, causing data loss.
        • Else, an IllegalArgumentException will be raised.
        Specified by:
        addOrUpdateDocumentType in interface IBigDataRepository
        Parameters:
        documentType - the document type to be added.
        force - indicates whether the update should be forced.
        See Also:
        DocumentTypes
      • getAllIndicesNames

        public java.lang.String[] getAllIndicesNames​(DocumentType type)
        Return all portal indices names for a type - for each locale - include null - generate a index name.
        Parameters:
        typeName - the type.
        Returns:
        all with indexed names.
        Since:
        11.1.0
      • getAllDocumentTypes

        public java.util.Map<java.lang.String,​? extends DocumentType> getAllDocumentTypes()
        Description copied from interface: IBigDataRepositorySPI
        Returns all document types, indexed by document type identifier.
        Specified by:
        getAllDocumentTypes in interface IBigDataRepositorySPI
        Returns:
        all document types, indexed by document type identifier.
        Since:
        8.1.0
      • startBatch

        public IBatchIndexer startBatch()
        Description copied from interface: IBigDataRepository
        Returns an indexer to perform bulk actions.
        The caller must assure IBatchIndexer.close() is called after the desired bulk operations were performed.

        Example of usage:

        IBatchIndexer batchIndexer = myBigDataRepository.startBatch(); try { // batch operations here } finally { batchIndexer.close(); }
        Or using try-with-resources:
        try(IBatchIndexer batchIndexer = myBigDataRepository.startBatch()) { // batch operations here }
        Specified by:
        startBatch in interface IBigDataRepository
        Returns:
        an indexer to perform bulk actions.
      • createSearchRequestBuilder

        public co.elastic.clients.elasticsearch.core.SearchRequest.Builder createSearchRequestBuilder​(SearchQuery searchQuery)
        Returns a new Elasticsearch search request builder for the given SearchQuery.
        Parameters:
        searchQuery - the search query.
        Returns:
        the Elasticsearch search request builder initialized accordingn to the given SearchQuery.
        Since:
        16.1.0
      • searchUsingScroll

        public <T> java.util.List<T> searchUsingScroll​(co.elastic.clients.elasticsearch.core.SearchRequest.Builder query,
                                                       int startAt,
                                                       int maxResults,
                                                       java.util.function.Function<co.elastic.clients.elasticsearch.core.search.ResponseBody<java.util.Map<java.lang.String,​java.lang.Object>>,​java.util.List<T>> collector)
        Performs the searching using scroll and collect data from all ranges.
        Parameters:
        query - the query.
        startAt - the start at position (1-based).
        maxResults - maximum results of query.
        collector - the function interface that will collect from response the required data.
        Returns:
        the required data.
        Since:
        11.2.0
      • getAutoCompleteSuggestions

        public java.util.List<java.lang.String> getAutoCompleteSuggestions​(SearchQuery searchQuery,
                                                                           AutoCompleteSuggestionConfig autoCompleteSuggestion)
        Description copied from interface: IBigDataSearcher
        Returns a list of auto complete suggestions for the given auto complete suggestion configuration and the search query.
        Specified by:
        getAutoCompleteSuggestions in interface IBigDataSearcher
        Parameters:
        searchQuery - the search query the auto complete request will be based on.
        autoCompleteSuggestion - the auto complete suggestion request.
        Returns:
        a list of auto complete suggestions for the given auto complete suggestion request.
      • getDelegate

        @Deprecated
        public org.elasticsearch.client.RestHighLevelClient getDelegate()
        Deprecated.
        Since 16.1.0 replaced by getDelegate(Class). For backwards compatibility, this method returns a RestHighLevelClient, but this behavior may change in the future, as that client was discontinued and may not be available in the future.
        Returns the underlying Elasticsearch client of this repository.
        Specified by:
        getDelegate in interface IBigDataRepository
        Returns:
        the underlying Elasticsearch client of this repository.
      • getDelegate

        public <T> T getDelegate​(java.lang.Class<T> type)
        Returns the underlying Elasticsearch client of this repository.
        Specified by:
        getDelegate in interface IBigDataRepository
        Parameters:
        type - the client type.
        Returns:
        the underlying Elasticsearch client of this repository.
        Since:
        16.1.0
      • getBulkProcessor

        public BulkProcessor getBulkProcessor()
        Returns an internal bulk processor used by this repository.
        Returns:
        bulk processor.
        Since:
        11.0.0
      • getSynonymsFiles

        public java.util.Map<java.util.Locale,​IFile> getSynonymsFiles()
        Description copied from interface: IBigDataRepositorySPI
        Return a map with all files that the portal need to create based the Locales of synonyms and Locales of portal.
        Specified by:
        getSynonymsFiles in interface IBigDataRepositorySPI
        Returns:
        a map that key is Locale, and, value is your file.
      • refreshIndices

        public void refreshIndices​(DocumentType documentType,
                                   java.util.Locale... locales)
        Refresh the indices of the given document type. If no locale is passed, all indices of the given document type will be refreshed.
        Parameters:
        documentType - the document type.
        locales - the locales.
        Since:
        12.0.0
      • refreshIndices

        public void refreshIndices​(java.lang.String documentTypeId,
                                   java.util.Locale... locales)
        Refresh the indices of the given document type. If no locale is passed, all indices of the given document type will be refreshed.
        Parameters:
        documentType - the document type.
        locales - the locales.
        Since:
        12.0.0
      • refreshIndices

        public void refreshIndices​(java.util.Collection<java.lang.String> documentTypeIds,
                                   java.util.Locale... locales)
        Refresh the indices of the given document type. If no locale is passed, all indices of the given document type will be refreshed.
        Parameters:
        documentTypeIds - the document type identifiers.
        locales - the locales.
        Since:
        12.2.0
      • getRequestOptions

        public org.elasticsearch.client.RequestOptions getRequestOptions()
        Returns the default request options.
        Returns:
        the default request options.
        Since:
        14.0.0
      • findDocumentTypesMissingIndices

        public java.util.Collection<java.lang.String> findDocumentTypesMissingIndices()
        Description copied from interface: IBigDataRepositorySPI
        Returns the missing indices that are supposed to exist due to existent document types.
        Specified by:
        findDocumentTypesMissingIndices in interface IBigDataRepositorySPI
        Returns:
        a collection with the missing indices name, or an empty collection if there is no index missing.
      • addDocumentToIndexQueue

        public void addDocumentToIndexQueue​(Document document)
        Adds a document that may be delayed until it is indexed.
        Parameters:
        document - the document.
        Since:
        11.0.0
      • deleteDocument

        public void deleteDocument​(DocumentType documentType,
                                   java.util.Locale locale,
                                   java.lang.String documentId)
        Description copied from interface: IBigDataIndexer
        Deletes a document from the index with the given specifications. If no such document exists, this method does nothing.
        Specified by:
        deleteDocument in interface IBigDataIndexer
        Parameters:
        documentType - the document's type.
        locale - the document's locale as set in its standard locale field. Must be null if the document does not have a locale specified.
        documentId - the document's identifier.
      • deleteDocumentsByFieldValue

        public void deleteDocumentsByFieldValue​(java.lang.String fieldId,
                                                java.lang.Object... values)
        Description copied from interface: IBigDataIndexer
        Deletes documents that are matched by one of the given values in the field of given field identifier.
        Specified by:
        deleteDocumentsByFieldValue in interface IBigDataIndexer
        Parameters:
        fieldId - the field identifier.
        values - the values.
      • deleteDocumentsByFieldValue

        public void deleteDocumentsByFieldValue​(java.lang.String fieldId,
                                                java.util.Collection<?> values)
        Description copied from interface: IBigDataIndexer
        Deletes documents that are matched by one of the given values in the field of given field identifier.
        Specified by:
        deleteDocumentsByFieldValue in interface IBigDataIndexer
        Parameters:
        fieldId - the field identifier.
        values - the values.
      • updateDocumentsByQuerySync

        public void updateDocumentsByQuerySync​(SearchQuery searchQuery,
                                               java.util.Map<java.lang.String,​java.lang.Object> fieldValues)
        Description copied from interface: IBigDataIndexer
        Updates documents that matches a SearchQuery updating their field values according to the fieldValues map.

        This operation is synchronous in relation to the completion of the update execution. Searches performed after this method returns may not reflect the update, since internal optimizations and behavior of the underlying big data storage may demand some time for the update to be visible to searches.

        Specified by:
        updateDocumentsByQuerySync in interface IBigDataIndexer
        Parameters:
        searchQuery - the search query.
        fieldValues - a map where the key is a field's full identifier and the value is the value to be set on the corresponding field. The value must be of a type compatible with the field type. If the value is null,
      • getBaseQuery

        protected co.elastic.clients.elasticsearch.core.SearchRequest.Builder getBaseQuery​(SearchQuery searchQuery)
        Returns a search request builder based on the given SearchQuery. Does not add sort, aggregations, start at and max rows.
        Parameters:
        searchQuery - the search query.
        Returns:
        a search request builder based on the given SearchQuery.
        Since:
        8.1.0
      • getQuery

        public co.elastic.clients.elasticsearch._types.query_dsl.Query getQuery​(SearchQuery searchQuery)
        Generates a Elasticsearch's Query generated according to a given LumisXP's SearchQuery.
        Parameters:
        searchQuery - the LumisXP's search query.
        Returns:
        the Elasticsearch's query.
        Since:
        16.1.0
      • executeSync

        @Deprecated
        protected <REQ,​RESP> RESP executeSync​(REQ request,
                                                    java.util.function.Function<org.elasticsearch.client.RestHighLevelClient,​lumis.portal.bigdata.elasticsearch.ElasticsearchIndexer.IResponseSupplier<REQ,​RESP>> supplierCreator)
        Deprecated.
        Since 16.1.0 due to deprecation of RestHighLevelClient.
        Executes the given request in a synchronous way.
        Type Parameters:
        REQ -
        RESP -
        Parameters:
        request - the request
        supplier - the response supplier (the code that actually performs the request)
        Returns:
        the response
        Since:
        14.0.0
      • executeSync

        @Deprecated
        protected <REQ,​RESP> RESP executeSync​(REQ request,
                                                    lumis.portal.bigdata.elasticsearch.ElasticsearchIndexer.IResponseSupplier<REQ,​RESP> supplier)
        Deprecated.
        Since 16.1.0 due to deprecation of RestHighLevelClient.
        Executes the given request in a synchronous way.
        Type Parameters:
        REQ -
        RESP -
        Parameters:
        request - the request
        supplier - the response supplier (the code that actually performs the request)
        Returns:
        the response
        Since:
        14.0.0
      • executeSync

        protected co.elastic.clients.elasticsearch.core.SearchResponse<java.util.Map<java.lang.String,​java.lang.Object>> executeSync​(co.elastic.clients.elasticsearch.core.SearchRequest query)
        Executes the given query and return the response.
        Parameters:
        query - the query
        Returns:
        the response
        Since:
        16.1.0
      • executeAsync

        @Deprecated
        protected <R extends org.elasticsearch.action.DocWriteRequest<R>> void executeAsync​(R request)
        Deprecated.
        Since 16.1.0 due to deprecation of RestHighLevelClient.
        Executes the given request in an asynchronous way (using a bulk processor).
        Type Parameters:
        R -
        Parameters:
        request - the request
        Since:
        14.0.0
      • executeAsync

        @Deprecated
        protected <R extends org.elasticsearch.action.DocWriteRequest<R>> void executeAsync​(R request,
                                                                                            boolean doFlush)
        Deprecated.
        Since 16.1.0 due to deprecation of RestHighLevelClient.
        Executes the given request in an asynchronous way (using a bulk processor).
        Type Parameters:
        R -
        Parameters:
        request - the request
        doFlush - indicates whether the bulk processor should be flushed
        Since:
        14.0.0