DATAES-88 - add method createIndex(Class<T> clazz, Object settings)

This commit is contained in:
Mohsin Husen
2014-05-01 11:46:20 +01:00
parent 3261af3f5a
commit 230c041d83
3 changed files with 63 additions and 18 deletions

View File

@@ -61,6 +61,14 @@ public interface ElasticsearchOperations {
*/
boolean createIndex(String indexName, Object settings);
/**
* Create an index for given class and Settings
*
* @param clazz
* @param settings
*/
<T> boolean createIndex(Class<T> clazz, Object settings);
/**
* Create mapping for a class
*

View File

@@ -643,6 +643,11 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
return createIndexRequestBuilder.execute().actionGet().isAcknowledged();
}
@Override
public <T> boolean createIndex(Class<T> clazz, Object settings) {
return createIndex(getPersistentEntityFor(clazz).getIndexName(), settings);
}
private <T> Map getDefaultSettings(ElasticsearchPersistentEntity<T> persistentEntity) {
return new MapBuilder<String, String>().put("index.number_of_shards", String.valueOf(persistentEntity.getShards()))
.put("index.number_of_replicas", String.valueOf(persistentEntity.getReplicas()))