Package com.privalia.qa.utils
Class ElasticSearchUtils
- java.lang.Object
-
- com.privalia.qa.utils.ElasticSearchUtils
-
public class ElasticSearchUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description ElasticSearchUtils()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connect()
Connect to ES.void
createMapping(String indexName, String mappingName, ArrayList<org.elasticsearch.common.xcontent.XContentBuilder> mappingSource)
Create a mapping over an indexboolean
createSingleIndex(String indexName)
Create an ES Index.void
deleteDocument(String indexName, String mappingName, String id)
Deletes a document by its id.boolean
dropAllIndexes()
boolean
dropSingleIndex(String indexName)
Drop an ES Indexboolean
existsMapping(String indexName, String mappingName)
Check if a mapping exists in an expecific index.org.elasticsearch.client.Client
getClient()
Get ES client(Connected previously).org.elasticsearch.common.settings.Settings
getSettings()
void
indexDocument(String indexName, String mappingName, String id, org.elasticsearch.common.xcontent.XContentBuilder document)
Indexes a document.boolean
indexExists(String indexName)
Check if an index exists in ESList<org.json.JSONObject>
searchSimpleFilterElasticsearchQuery(String indexName, String mappingName, String columnName, Object value, String filterType)
Simulate a SELET * FROM index.mapping WHERE (One simple filter)void
setHost(String host)
void
setNativePort(Integer port)
void
setSettings(LinkedHashMap<String,Object> settings)
Set settings about ES connector.
-
-
-
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)
-
connect
public void connect() throws UnknownHostException
Connect to ES.- Throws:
UnknownHostException
- the unknown host exception
-
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 namemappingName
- the mapping namemappingSource
- 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 namemappingName
- 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 namemappingName
- The mapping namecolumnName
- The column namevalue
- The valuefilterType
- [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 namemappingName
- the mapping nameid
- unique identifier of the documentdocument
- the document- Throws:
Exception
- exception
-
-