DATAES-8 : Add support for Index level configuration

This commit is contained in:
Mohsin Husen
2013-05-12 09:43:26 +01:00
parent e72521ba48
commit 8c31761308
9 changed files with 43 additions and 10 deletions

View File

@@ -35,5 +35,8 @@ public @interface Document {
String indexName();
String type() default "";
short shards() default 1;
short replicas() default 5;
String refreshInterval() default "1s";
String indexStoreType() default "fs";
}

View File

@@ -382,9 +382,16 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
private <T> boolean createIndexWithSettings(Class<T> clazz) {
ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz);
return client.admin().indices().create(Requests.createIndexRequest(persistentEntity.getIndexName()).
settings(new MapBuilder<String, String>()
.put("index.store.type", persistentEntity.getIndexStoreType())
.map())).actionGet().acknowledged();
settings(getSettings(persistentEntity))).actionGet().acknowledged();
}
private <T> Map getSettings(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()))
.put("index.refresh_interval", persistentEntity.getRefreshInterval())
.put("index.store.type", persistentEntity.getIndexStoreType())
.map();
}
private <T> SearchRequestBuilder prepareSearch(Query query, Class<T> clazz){

View File

@@ -27,6 +27,9 @@ public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, El
String getIndexName();
String getIndexType();
short getShards();
short getReplicas();
String getRefreshInterval();
String getIndexStoreType();
ElasticsearchPersistentProperty getVersionProperty();
}

View File

@@ -45,6 +45,9 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
private final StandardEvaluationContext context;
private String indexName;
private String indexType;
private short shards;
private short replicas;
private String refreshInterval;
private String indexStoreType;
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
@@ -56,6 +59,9 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
Assert.hasText(document.indexName(), " Unknown indexName. Make sure the indexName is defined. e.g @Document(indexName=\"foo\")");
this.indexName = typeInformation.getType().getAnnotation(Document.class).indexName();
this.indexType = hasText(document.type())? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH);
this.shards = typeInformation.getType().getAnnotation(Document.class).shards();
this.replicas = typeInformation.getType().getAnnotation(Document.class).replicas();
this.refreshInterval = typeInformation.getType().getAnnotation(Document.class).refreshInterval();
this.indexStoreType = typeInformation.getType().getAnnotation(Document.class).indexStoreType();
}
}
@@ -77,10 +83,26 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
return indexType;
}
@Override
public String getIndexStoreType() {
return indexStoreType;
}
@Override
public short getShards() {
return shards;
}
@Override
public short getReplicas() {
return replicas;
}
@Override
public String getRefreshInterval() {
return refreshInterval;
}
@Override
public void addPersistentProperty(ElasticsearchPersistentProperty property) {
super.addPersistentProperty(property);