DATAES-19 : Delete specific type in an index, Type exists check
This commit is contained in:
@@ -203,13 +203,21 @@ public interface ElasticsearchOperations {
|
||||
|
||||
/**
|
||||
* Deletes an index for given entity
|
||||
*
|
||||
*
|
||||
* @param clazz
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
<T> boolean deleteIndex(Class<T> clazz);
|
||||
|
||||
/**
|
||||
* Deletes a type in an index
|
||||
*
|
||||
* @param index
|
||||
* @param type
|
||||
*/
|
||||
void deleteType(String index, String type);
|
||||
|
||||
/**
|
||||
* check if index is exists
|
||||
*
|
||||
@@ -219,6 +227,15 @@ public interface ElasticsearchOperations {
|
||||
*/
|
||||
<T> boolean indexExists(Class<T> clazz);
|
||||
|
||||
/**
|
||||
* check if type is exists in an index
|
||||
*
|
||||
* @param index
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
boolean typeExists(String index, String type);
|
||||
|
||||
/**
|
||||
* refresh the index
|
||||
*
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.apache.commons.collections.CollectionUtils;
|
||||
import org.codehaus.jackson.map.DeserializationConfig;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
|
||||
import org.elasticsearch.action.bulk.BulkItemResponse;
|
||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
@@ -252,6 +253,12 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
return indexExists(getPersistentEntityFor(clazz).getIndexName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeExists(String index, String type) {
|
||||
return client.admin().cluster().prepareState().execute().actionGet()
|
||||
.getState().metaData().index(index).mappings().containsKey(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean deleteIndex(Class<T> clazz) {
|
||||
String indexName = getPersistentEntityFor(clazz).getIndexName();
|
||||
@@ -261,6 +268,15 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteType(String index, String type){
|
||||
Map mappings = client.admin().cluster().prepareState().execute().actionGet()
|
||||
.getState().metaData().index(index).mappings();
|
||||
if (mappings.containsKey(type)) {
|
||||
client.admin().indices().deleteMapping(new DeleteMappingRequest(index).type(type)).actionGet();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String delete(String indexName, String type, String id) {
|
||||
return client.prepareDelete(indexName, type, id).execute().actionGet().getId();
|
||||
|
||||
Reference in New Issue
Block a user