DATAES-8 : Add support for Index level configuration
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user