DATAES-72 - Enhance Delete Index in ElasticsearchTemplate
added deleteIndex(String indexName) and indexExist(String indexName) methods
This commit is contained in:
@@ -275,6 +275,14 @@ public interface ElasticsearchOperations {
|
||||
*/
|
||||
<T> boolean deleteIndex(Class<T> clazz);
|
||||
|
||||
/**
|
||||
* Deletes an index for given indexName
|
||||
*
|
||||
* @param indexName
|
||||
* @return
|
||||
*/
|
||||
boolean deleteIndex(String indexName);
|
||||
|
||||
/**
|
||||
* Deletes a type in an index
|
||||
*
|
||||
@@ -292,6 +300,14 @@ public interface ElasticsearchOperations {
|
||||
*/
|
||||
<T> boolean indexExists(Class<T> clazz);
|
||||
|
||||
/**
|
||||
* check if index is exists for given IndexName
|
||||
*
|
||||
* @param indexName
|
||||
* @return
|
||||
*/
|
||||
boolean indexExists(String indexName);
|
||||
|
||||
/**
|
||||
* check if type is exists in an index
|
||||
*
|
||||
|
||||
@@ -351,6 +351,11 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
return indexExists(getPersistentEntityFor(clazz).getIndexName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean indexExists(String indexName) {
|
||||
return client.admin().indices().exists(indicesExistsRequest(indexName)).actionGet().isExists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeExists(String index, String type) {
|
||||
return client.admin().cluster().prepareState().execute().actionGet()
|
||||
@@ -359,7 +364,11 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
|
||||
@Override
|
||||
public <T> boolean deleteIndex(Class<T> clazz) {
|
||||
String indexName = getPersistentEntityFor(clazz).getIndexName();
|
||||
return deleteIndex(getPersistentEntityFor(clazz).getIndexName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteIndex(String indexName) {
|
||||
if (indexExists(indexName)) {
|
||||
return client.admin().indices().delete(new DeleteIndexRequest(indexName)).actionGet().isAcknowledged();
|
||||
}
|
||||
@@ -533,10 +542,6 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
return indexExists(getPersistentEntityFor(clazz).getIndexName()) || createIndexWithSettings(clazz);
|
||||
}
|
||||
|
||||
private boolean indexExists(String indexName) {
|
||||
return client.admin().indices().exists(indicesExistsRequest(indexName)).actionGet().isExists();
|
||||
}
|
||||
|
||||
private <T> boolean createIndexWithSettings(Class<T> clazz) {
|
||||
ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz);
|
||||
return client.admin().indices()
|
||||
|
||||
Reference in New Issue
Block a user