Class ElasticClient


  • public class ElasticClient
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ElasticClient​(java.lang.String strServerUrl)
      Constructor
      ElasticClient​(java.lang.String strServerUrl, java.lang.String strServerLogin, java.lang.String strServerPwd)
      Basic Authentification constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAliasOnIndex​(AliasActions aliasActions)  
      boolean aliasExists​(java.lang.String strAlias)
      Check if a given alias exists
      void create​(java.lang.String strIndex, java.lang.String strId, java.lang.Object object)
      Create a document of given type into a given index at the given id
      void createMappings​(java.lang.String strIndex, java.lang.String strJsonMappings)  
      void deleteAlias​(java.lang.String strIndex, java.lang.String alias)  
      void deleteDocument​(java.lang.String strIndex, java.lang.String strId)
      Delete a document based on its id in the index
      void deleteIndex​(java.lang.String strIndex)
      Delete a given index
      java.lang.String get​(java.lang.String strIndex, java.lang.String strId)  
      java.lang.String getAlias​(java.lang.String alias)  
      java.lang.String getIndexedIdentitiesNumber​(java.lang.String strIndex)  
      void indexByBulk​(java.lang.String strIndex, java.util.List<BulkAction> bulkActions)
      perform a bulk indexing of documents : this is used for indexing thousand doc with one HTTP call
      boolean isAlive()  
      boolean isExists​(java.lang.String strIndex)
      Check if a given index exists
      boolean isWriteable​(java.lang.String strIndex)
      Check if a given index is not in read only mode
      Responses multiSearch​(java.lang.String strIndex, java.util.List<MultiSearchAction> searchActions)
      perform a multi search of documents : used to perform several query with a single http call
      Response search​(java.lang.String strIndex, java.lang.Object search)
      Search a document of given type into a given index
      void update​(java.lang.String strIndex, java.lang.String strId, java.lang.Object object)
      Partial Updates to Documents
      void updateSettings​(java.lang.String strIndex, java.lang.String strJsonSettings)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ElasticClient

        public ElasticClient​(java.lang.String strServerUrl)
        Constructor
        Parameters:
        strServerUrl - The Elastic server URL
      • ElasticClient

        public ElasticClient​(java.lang.String strServerUrl,
                             java.lang.String strServerLogin,
                             java.lang.String strServerPwd)
        Basic Authentification constructor
        Parameters:
        strServerUrl - The Elastic server URL
        strServerLogin - Login
        strServerPwd - Password
    • Method Detail

      • create

        public void create​(java.lang.String strIndex,
                           java.lang.String strId,
                           java.lang.Object object)
                    throws ElasticClientException
        Create a document of given type into a given index at the given id
        Parameters:
        strIndex - The index
        strId - The document id
        object - The document
        Throws:
        ElasticClientException - If a problem occurs connecting Elastic
      • indexByBulk

        public void indexByBulk​(java.lang.String strIndex,
                                java.util.List<BulkAction> bulkActions)
                         throws ElasticClientException
        perform a bulk indexing of documents : this is used for indexing thousand doc with one HTTP call
        Parameters:
        strIndex - the elk index name
        bulkActions - the actions
        Throws:
        ElasticClientException
      • deleteIndex

        public void deleteIndex​(java.lang.String strIndex)
                         throws ElasticClientException
        Delete a given index
        Parameters:
        strIndex - The index
        Throws:
        ElasticClientException - If a problem occurs connecting Elastic
      • deleteDocument

        public void deleteDocument​(java.lang.String strIndex,
                                   java.lang.String strId)
                            throws ElasticClientException
        Delete a document based on its id in the index
        Parameters:
        strIndex - The index
        strId - The id
        Throws:
        ElasticClientException - If a problem occurs connecting Elastic
      • update

        public void update​(java.lang.String strIndex,
                           java.lang.String strId,
                           java.lang.Object object)
                    throws ElasticClientException
        Partial Updates to Documents
        Parameters:
        strIndex - The index
        strId - The document id
        object - The document
        Throws:
        ElasticClientException - If a problem occurs connecting Elastic
      • get

        public java.lang.String get​(java.lang.String strIndex,
                                    java.lang.String strId)
                             throws ElasticClientException
        Parameters:
        strIndex - the index of the document
        strId - the id of the document
        Returns:
        the document if any
        Throws:
        ElasticClientException
      • isExists

        public boolean isExists​(java.lang.String strIndex)
                         throws ElasticClientException
        Check if a given index exists
        Parameters:
        strIndex - The index
        Returns:
        if th index exists
        Throws:
        ElasticClientException - If a problem occurs connecting Elastic
      • isWriteable

        public boolean isWriteable​(java.lang.String strIndex)
        Check if a given index is not in read only mode
        Parameters:
        strIndex - The index
        Returns:
        true if the index exists and is writable
      • search

        public Response search​(java.lang.String strIndex,
                               java.lang.Object search)
                        throws ElasticClientException
        Search a document of given type into a given index
        Parameters:
        strIndex - The index
        search - search request
        Returns:
        The JSON response from Elastic
        Throws:
        ElasticClientException - If a problem occurs connecting Elastic
      • multiSearch

        public Responses multiSearch​(java.lang.String strIndex,
                                     java.util.List<MultiSearchAction> searchActions)
                              throws ElasticClientException
        perform a multi search of documents : used to perform several query with a single http call
        Parameters:
        strIndex - the elk index name
        searchActions - the actions
        Returns:
        the reponse of Elk server
        Throws:
        ElasticClientException
      • aliasExists

        public boolean aliasExists​(java.lang.String strAlias)
        Check if a given alias exists
        Parameters:
        strAlias - The indexThe alias
        Returns:
        if th index exists
      • isAlive

        public boolean isAlive()