Class ElasticSearchUtils


  • public class ElasticSearchUtils
    extends Object
    • Constructor Detail

      • ElasticSearchUtils

        public ElasticSearchUtils()
        Default constructor.
    • Method Detail

      • getSettings

        public org.elasticsearch.common.settings.Settings getSettings()
      • setSettings

        public void setSettings​(LinkedHashMap<String,​Object> settings)
        Set settings about ES connector.
        Parameters:
        settings - : LinkedHashMap with all the settings about ES connection
      • setHost

        public void setHost​(String host)
      • setNativePort

        public void setNativePort​(Integer port)
      • getClient

        public org.elasticsearch.client.Client getClient()
        Get ES client(Connected previously).
        Returns:
        es client
      • createSingleIndex

        public boolean createSingleIndex​(String indexName)
                                  throws org.elasticsearch.ElasticsearchException
        Create an ES Index.
        Parameters:
        indexName - the index name
        Returns:
        true if the index has been created and false if the index has not been created.
        Throws:
        org.elasticsearch.ElasticsearchException - the elasticsearch exception
      • dropSingleIndex

        public boolean dropSingleIndex​(String indexName)
                                throws org.elasticsearch.ElasticsearchException
        Drop an ES Index
        Parameters:
        indexName - the index name
        Returns:
        true if the index exists
        Throws:
        org.elasticsearch.ElasticsearchException - the elasticsearch exception
      • dropAllIndexes

        public boolean dropAllIndexes()
      • indexExists

        public boolean indexExists​(String indexName)
        Check if an index exists in ES
        Parameters:
        indexName - the index name
        Returns:
        true if the index exists or false if the index does not exits.
      • createMapping

        public void createMapping​(String indexName,
                                  String mappingName,
                                  ArrayList<org.elasticsearch.common.xcontent.XContentBuilder> mappingSource)
        Create a mapping over an index
        Parameters:
        indexName - the index name
        mappingName - the mapping name
        mappingSource - the data that has to be inserted in the mapping.
      • existsMapping

        public boolean existsMapping​(String indexName,
                                     String mappingName)
        Check if a mapping exists in an expecific index.
        Parameters:
        indexName - the index name
        mappingName - the mapping name
        Returns:
        true if the mapping exists and false in other case
      • searchSimpleFilterElasticsearchQuery

        public List<org.json.JSONObject> searchSimpleFilterElasticsearchQuery​(String indexName,
                                                                              String mappingName,
                                                                              String columnName,
                                                                              Object value,
                                                                              String filterType)
                                                                       throws Exception
        Simulate a SELET * FROM index.mapping WHERE (One simple filter)
        Parameters:
        indexName - The index name
        mappingName - The mapping name
        columnName - The column name
        value - The value
        filterType - [equals, gt, gte, lt, lte]
        Returns:
        ArrayList with all the rows(One element of the ArrayList is a JSON document)
        Throws:
        Exception - Exception
      • indexDocument

        public void indexDocument​(String indexName,
                                  String mappingName,
                                  String id,
                                  org.elasticsearch.common.xcontent.XContentBuilder document)
                           throws Exception
        Indexes a document.
        Parameters:
        indexName - the index name
        mappingName - the mapping name
        id - unique identifier of the document
        document - the document
        Throws:
        Exception - exception
      • deleteDocument

        public void deleteDocument​(String indexName,
                                   String mappingName,
                                   String id)
        Deletes a document by its id.
        Parameters:
        indexName - the index name
        mappingName - the mapping name
        id - the id