java.lang.Object
fr.paris.lutece.plugins.libraryelastic.util.Elastic

public class Elastic extends Object
Elastic
  • Constructor Details

    • Elastic

      public Elastic(String strServerUrl)
      Constructor
      Parameters:
      strServerUrl - The Elastic server URL
    • Elastic

      public Elastic(String strServerUrl, String strServerLogin, String strServerPwd)
      Basic Authentification constructor
      Parameters:
      strServerUrl - The Elastic server URL
      strServerLogin - Login
      strServerPwd - Password
  • Method Details

    • create

      public String create(String strIndex, Object object) throws ElasticClientException
      Create a document of given type into a given index
      Parameters:
      strIndex - The index
      object - The document
      Returns:
      The JSON response from Elastic
      Throws:
      ElasticClientException - If a problem occurs connecting Elastic
    • create

      public String create(String strIndex, String strId, 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
      Returns:
      The JSON response from Elastic
      Throws:
      ElasticClientException - If a problem occurs connecting Elastic
    • createByBulk

      public String createByBulk(String strIndex, BulkRequest bulkRequest) 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
      bulkRequest - the bulkRequest
      Returns:
      the reponse of Elk server
      Throws:
      ElasticClientException
    • deleteIndex

      public String deleteIndex(String strIndex) throws ElasticClientException
      Delete a given index
      Parameters:
      strIndex - The index
      Returns:
      The JSON response from Elastic
      Throws:
      ElasticClientException - If a problem occurs connecting Elastic
    • deleteDocument

      public String deleteDocument(String strIndex, String strId) throws ElasticClientException
      Delete a document based on its id in the index
      Parameters:
      strIndex - The index
      strId - The id
      Returns:
      The JSON response from Elastic
      Throws:
      ElasticClientException - If a problem occurs connecting Elastic
    • deleteByQuery

      public String deleteByQuery(String strIndex, String strQuery) throws ElasticClientException
      Delete a documents by Query
      Parameters:
      strIndex - The index
      strQuery - The Query
      Returns:
      The JSON response from Elastic
      Throws:
      ElasticClientException - If a problem occurs connecting Elastic
    • partialUpdate

      public String partialUpdate(String strIndex, String strId, Object object) throws ElasticClientException
      Partial Updates to Documents
      Parameters:
      strIndex - The index
      strId - The document id
      object - The document
      Returns:
      The JSON response from Elastic
      Throws:
      ElasticClientException - If a problem occurs connecting Elastic
    • isExists

      public boolean isExists(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
    • search

      public String search(String strIndex, SearchRequest 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
    • search

      public String search(String strIndex, String searchRequest) throws ElasticClientException
      Search
      Parameters:
      strIndex - The index
      strSearchRequest - search request
      Returns:
      The JSON response from Elastic
      Throws:
      ElasticClientException - If a problem occurs connecting Elastic
    • suggest

      public String suggest(String strIndex, AbstractSuggestRequest suggest) throws ElasticClientException
      suggest a list of document of given type into a given index The suggest is done with a _search request with size set to 0 to avoid fetch in 'hits' so be careful with the JSON result
      Parameters:
      strIndex - The index
      suggest - suggest request
      Returns:
      The JSON response from Elastic
      Throws:
      ElasticClientException - If a problem occurs connecting Elastic
    • suggest

      public String suggest(String strIndex, String strJSON) throws ElasticClientException
      suggest a list of document of given type into a given index The suggest is done with a _search request with size set to 0 to avoid fetch in 'hits' so be careful with the JSON result
      Parameters:
      strIndex - The index
      strJSON - suggest request
      Returns:
      The JSON response from Elastic
      Throws:
      ElasticClientException - If a problem occurs connecting Elastic
    • createMappings

      public String createMappings(String strIndex, String strJsonMappings) throws ElasticClientException
      Parameters:
      strIndex -
      strJsonMappings -
      Returns:
      Throws:
      ElasticClientException