Class ElasticsearchRepository

    • Field Detail

      • NATIVE_TEMPLATES_SYNONYMS_LOCALES

        public static final List<Locale> NATIVE_TEMPLATES_SYNONYMS_LOCALES
      • client

        protected org.elasticsearch.client.RestHighLevelClient client
      • requestOptions

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

      • ElasticsearchRepository

        public ElasticsearchRepository()
    • Method Detail

      • init

        public void init​(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.
      • deleteIndicesTemplates

        public void deleteIndicesTemplates()
        Delete the all index templates.
        Since:
        11.1.0
      • getSearchAliasName

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

        public 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​(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​(Locale locale)
        Deletes the indices related to the given locale.
        Parameters:
        locale - the locale.
        Since:
        8.1.0
      • getIndexTemplateSettings

        public String getIndexTemplateSettings​(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 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
      • 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.
      • getElasticsearchQuery

        public org.elasticsearch.action.search.SearchRequest getElasticsearchQuery​(SearchQuery searchQuery)
        Returns the Elasticsearch search query for the given SearchQuery.
        Parameters:
        searchQuery - the search query.
        Returns:
        the Elasticsearch search query for the given SearchQuery.
      • searchUsingScroll

        public <T> List<T> searchUsingScroll​(org.elasticsearch.action.search.SearchRequest query,
                                             int startAt,
                                             int maxResults,
                                             java.util.function.Function<org.elasticsearch.action.search.SearchResponse,​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 List<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

        public org.elasticsearch.client.RestHighLevelClient getDelegate()
        Returns the underlying Elasticsearch client of this repository.
        Specified by:
        getDelegate in interface IBigDataRepository
        Returns:
        the underlying Elasticsearch client of this repository.
      • getBulkProcessor

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

        public Map<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,
                                   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​(String documentTypeId,
                                   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​(Collection<String> documentTypeIds,
                                   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
      • 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,
                                   Locale locale,
                                   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​(String fieldId,
                                                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.
      • updateDocumentsByQuerySync

        public void updateDocumentsByQuerySync​(SearchQuery searchQuery,
                                               Map<String,​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 org.elasticsearch.action.search.SearchRequest 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
      • getQueryBuilder

        public org.elasticsearch.index.query.QueryBuilder getQueryBuilder​(SearchQuery searchQuery)
        Generates a Elasticsearch's QueryBuilder initialized according to a LumisXP's SearchQuery.
        Parameters:
        searchQuery - the LumisXP's search query.
        Returns:
        the Elasticsearch's query builder.
        Since:
        11.0.0
      • executeSync

        protected <REQ,​RESP> RESP executeSync​(REQ request,
                                                    java.util.function.Function<org.elasticsearch.client.RestHighLevelClient,​lumis.portal.bigdata.elasticsearch.ElasticsearchIndexer.IResponseSupplier<REQ,​RESP>> supplierCreator)
        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 <REQ,​RESP> RESP executeSync​(REQ request,
                                                    lumis.portal.bigdata.elasticsearch.ElasticsearchIndexer.IResponseSupplier<REQ,​RESP> supplier)
        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 org.elasticsearch.action.search.SearchResponse executeSync​(org.elasticsearch.action.search.SearchRequest query)
        Executes the given query and return the response.
        Parameters:
        query - the query
        Returns:
        the response
        Since:
        14.0.0
      • executeAsync

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

        protected <R extends org.elasticsearch.action.DocWriteRequest<R>> void executeAsync​(R request,
                                                                                            boolean doFlush)
        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