diff --git a/src/main/java/org/springframework/data/elasticsearch/annotations/Document.java b/src/main/java/org/springframework/data/elasticsearch/annotations/Document.java index 4c785437e..d25496eef 100644 --- a/src/main/java/org/springframework/data/elasticsearch/annotations/Document.java +++ b/src/main/java/org/springframework/data/elasticsearch/annotations/Document.java @@ -35,4 +35,5 @@ public @interface Document { String indexName(); String type() default ""; + String indexStoreType() default "fs"; } diff --git a/src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java b/src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java index 337c0ef05..5f841ac0c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java @@ -17,6 +17,7 @@ package org.springframework.data.elasticsearch.client; import org.elasticsearch.client.Client; import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.settings.ImmutableSettings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.DisposableBean; @@ -36,7 +37,8 @@ public class NodeClientFactoryBean implements FactoryBean, Initializ private static final Logger logger = LoggerFactory.getLogger(NodeClientFactoryBean.class); private boolean local; - private boolean purgeDataOnShutdown; + private boolean enableHttp; + private String clusterName; private NodeClient nodeClient; NodeClientFactoryBean() { @@ -63,15 +65,23 @@ public class NodeClientFactoryBean implements FactoryBean, Initializ @Override public void afterPropertiesSet() throws Exception { - nodeClient = (NodeClient) nodeBuilder().local(this.local).data(!this.purgeDataOnShutdown).node().client(); + ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder() + .put("http.enabled", String.valueOf(this.enableHttp)); + + nodeClient = (NodeClient) nodeBuilder().settings(settings) + .clusterName(this.clusterName).local(this.local).node().client(); } public void setLocal(boolean local) { this.local = local; } - public void setPurgeDataOnShutdown(boolean purgeDataOnShutdown) { - this.purgeDataOnShutdown = purgeDataOnShutdown; + public void setEnableHttp(boolean enableHttp) { + this.enableHttp = enableHttp; + } + + public void setClusterName(String clusterName) { + this.clusterName = clusterName; } @Override diff --git a/src/main/java/org/springframework/data/elasticsearch/config/NodeClientBeanDefinitionParser.java b/src/main/java/org/springframework/data/elasticsearch/config/NodeClientBeanDefinitionParser.java index 66ef74461..ffc03b3d6 100644 --- a/src/main/java/org/springframework/data/elasticsearch/config/NodeClientBeanDefinitionParser.java +++ b/src/main/java/org/springframework/data/elasticsearch/config/NodeClientBeanDefinitionParser.java @@ -41,7 +41,8 @@ public class NodeClientBeanDefinitionParser extends AbstractBeanDefinitionParser private void setLocalSettings(Element element, BeanDefinitionBuilder builder) { builder.addPropertyValue("local", Boolean.valueOf(element.getAttribute("local"))); - builder.addPropertyValue("purgeDataOnShutdown", Boolean.valueOf(element.getAttribute("purge-data-on-shutdown"))); + builder.addPropertyValue("clusterName", element.getAttribute("cluster-name")); + builder.addPropertyValue("enableHttp",Boolean.valueOf(element.getAttribute("http-enabled"))); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java index 1ba5978a7..76e1f0060 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java @@ -96,7 +96,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations { @Override public boolean createIndex(Class clazz) { ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz); - return createIndexIfNotCreated(persistentEntity.getIndexName()); + return createIndexIfNotCreated(clazz); } @Override @@ -369,8 +369,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations { return searchRequest.setQuery(query).execute().actionGet(); } - private boolean createIndexIfNotCreated(String indexName) { - return indexExists(indexName) || createIndex(indexName); + private boolean createIndexIfNotCreated(Class clazz) { + return indexExists(getPersistentEntityFor(clazz).getIndexName()) || createIndexWithSettings(clazz); } private boolean indexExists(String indexName) { @@ -379,9 +379,12 @@ public class ElasticsearchTemplate implements ElasticsearchOperations { .exists(indicesExistsRequest(indexName)).actionGet().exists(); } - private boolean createIndex(String indexName) { - return client.admin().indices().create(Requests.createIndexRequest(indexName). - settings(new MapBuilder().put("index.refresh_interval", "-1").map())).actionGet().acknowledged(); + private boolean createIndexWithSettings(Class clazz) { + ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz); + return client.admin().indices().create(Requests.createIndexRequest(persistentEntity.getIndexName()). + settings(new MapBuilder() + .put("index.store.type", persistentEntity.getIndexStoreType()) + .map())).actionGet().acknowledged(); } private SearchRequestBuilder prepareSearch(Query query, Class clazz){ diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/ElasticsearchPersistentEntity.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/ElasticsearchPersistentEntity.java index 8354587fa..067f2bc73 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/ElasticsearchPersistentEntity.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/ElasticsearchPersistentEntity.java @@ -27,5 +27,6 @@ public interface ElasticsearchPersistentEntity extends PersistentEntity extends BasicPersistentEntit private final StandardEvaluationContext context; private String indexName; private String indexType; + private String indexStoreType; public SimpleElasticsearchPersistentEntity(TypeInformation typeInformation) { super(typeInformation); @@ -55,6 +56,7 @@ public class SimpleElasticsearchPersistentEntity 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.indexStoreType = typeInformation.getType().getAnnotation(Document.class).indexStoreType(); } } @@ -75,6 +77,10 @@ public class SimpleElasticsearchPersistentEntity extends BasicPersistentEntit return indexType; } + public String getIndexStoreType() { + return indexStoreType; + } + @Override public void addPersistentProperty(ElasticsearchPersistentProperty property) { super.addPersistentProperty(property); diff --git a/src/main/resources/org/springframework/data/elasticsearch/config/spring-elasticsearch-1.0.xsd b/src/main/resources/org/springframework/data/elasticsearch/config/spring-elasticsearch-1.0.xsd index 3f44b947e..8917e3dbf 100644 --- a/src/main/resources/org/springframework/data/elasticsearch/config/spring-elasticsearch-1.0.xsd +++ b/src/main/resources/org/springframework/data/elasticsearch/config/spring-elasticsearch-1.0.xsd @@ -45,7 +45,8 @@ - + + diff --git a/src/test/java/org/springframework/data/elasticsearch/Book.java b/src/test/java/org/springframework/data/elasticsearch/Book.java index d2937eadd..b0bcefd0b 100644 --- a/src/test/java/org/springframework/data/elasticsearch/Book.java +++ b/src/test/java/org/springframework/data/elasticsearch/Book.java @@ -21,7 +21,7 @@ import org.springframework.data.elasticsearch.annotations.Document; * @author Rizwan Idrees * @author Mohsin Husen */ -@Document(indexName = "book",type = "book") +@Document(indexName = "book",type = "book", indexStoreType = "memory") public class Book { @Id diff --git a/src/test/java/org/springframework/data/elasticsearch/DoubleIDEntity.java b/src/test/java/org/springframework/data/elasticsearch/DoubleIDEntity.java index 4d5be8ae6..fd6ff7355 100644 --- a/src/test/java/org/springframework/data/elasticsearch/DoubleIDEntity.java +++ b/src/test/java/org/springframework/data/elasticsearch/DoubleIDEntity.java @@ -20,7 +20,7 @@ import org.springframework.data.annotation.Version; import org.springframework.data.elasticsearch.annotations.Document; -@Document(indexName = "double-keyed-entity", type = "double-keyed-entity") +@Document(indexName = "double-keyed-entity", type = "double-keyed-entity", indexStoreType = "memory") public class DoubleIDEntity { diff --git a/src/test/java/org/springframework/data/elasticsearch/IntegerIDEntity.java b/src/test/java/org/springframework/data/elasticsearch/IntegerIDEntity.java index 8b13db8d2..b6fe1dc07 100644 --- a/src/test/java/org/springframework/data/elasticsearch/IntegerIDEntity.java +++ b/src/test/java/org/springframework/data/elasticsearch/IntegerIDEntity.java @@ -22,7 +22,7 @@ import org.springframework.data.annotation.Version; import org.springframework.data.elasticsearch.annotations.Document; -@Document(indexName = "integer-keyed-entity", type = "integer-keyed-entity") +@Document(indexName = "integer-keyed-entity", type = "integer-keyed-entity", indexStoreType = "memory") public class IntegerIDEntity { diff --git a/src/test/java/org/springframework/data/elasticsearch/SampleEntity.java b/src/test/java/org/springframework/data/elasticsearch/SampleEntity.java index 58bf8f377..eaa19ad6b 100644 --- a/src/test/java/org/springframework/data/elasticsearch/SampleEntity.java +++ b/src/test/java/org/springframework/data/elasticsearch/SampleEntity.java @@ -25,7 +25,7 @@ import org.springframework.data.elasticsearch.annotations.Document; * @author Rizwan Idrees * @author Mohsin Husen */ -@Document(indexName = "test-index", type = "test-type") +@Document(indexName = "test-index", type = "test-type", indexStoreType = "memory") public class SampleEntity { @Id diff --git a/src/test/java/org/springframework/data/elasticsearch/SampleMappingEntity.java b/src/test/java/org/springframework/data/elasticsearch/SampleMappingEntity.java index 67be7646c..3822ca183 100644 --- a/src/test/java/org/springframework/data/elasticsearch/SampleMappingEntity.java +++ b/src/test/java/org/springframework/data/elasticsearch/SampleMappingEntity.java @@ -24,7 +24,7 @@ import org.springframework.data.elasticsearch.annotations.Field; * @author Rizwan Idrees * @author Mohsin Husen */ -@Document(indexName = "test-mapping", type = "mapping") +@Document(indexName = "test-mapping", type = "mapping", indexStoreType = "memory") public class SampleMappingEntity { @Id diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java index a57d9bc74..0f76dad58 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java @@ -25,17 +25,13 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; - import java.util.ArrayList; import java.util.List; import static org.apache.commons.lang.RandomStringUtils.randomNumeric; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.hamcrest.Matchers.*; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author Rizwan Idrees * @author Mohsin Husen @@ -56,7 +52,6 @@ public class CriteriaQueryTests { elasticsearchTemplate.refresh(SampleEntity.class, true); } - @Test public void shouldPerformAndOperation(){ //given diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/IntegerIDRepository.java b/src/test/java/org/springframework/data/elasticsearch/repositories/IntegerIDRepository.java index 6dab0d57b..090016c66 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/IntegerIDRepository.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/IntegerIDRepository.java @@ -16,7 +16,6 @@ package org.springframework.data.elasticsearch.repositories; import org.springframework.data.elasticsearch.IntegerIDEntity; -import org.springframework.data.elasticsearch.SampleEntity; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; public interface IntegerIDRepository extends ElasticsearchRepository { diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/DoubleIDRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/DoubleIDRepositoryTests.java index 00fdc986e..25ad9be80 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/DoubleIDRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/DoubleIDRepositoryTests.java @@ -377,13 +377,13 @@ public class DoubleIDRepositoryTests { Double documentId = RandomUtils.nextDouble(); DoubleIDEntity sampleEntity = new DoubleIDEntity(); sampleEntity.setId(documentId); - sampleEntity.setMessage("A. hello world."); + sampleEntity.setMessage("abc"); repository.save(sampleEntity); Double documentId2 = RandomUtils.nextDouble(); DoubleIDEntity sampleEntity2 = new DoubleIDEntity(); sampleEntity2.setId(documentId2); - sampleEntity2.setMessage("B.hello world."); + sampleEntity2.setMessage("xyz"); repository.save(sampleEntity2); //when Iterable sampleEntities=repository.findAll(new Sort(new Sort.Order(Sort.Direction.ASC,"message"))); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/IntegerIDRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/IntegerIDRepositoryTests.java index f9a749620..e18e22023 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/IntegerIDRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/IntegerIDRepositoryTests.java @@ -377,13 +377,13 @@ public class IntegerIDRepositoryTests { Integer documentId = RandomUtils.nextInt(); IntegerIDEntity sampleEntity = new IntegerIDEntity(); sampleEntity.setId(documentId); - sampleEntity.setMessage("A. hello world."); + sampleEntity.setMessage("hello"); repository.save(sampleEntity); Integer documentId2 = RandomUtils.nextInt(); IntegerIDEntity sampleEntity2 = new IntegerIDEntity(); sampleEntity2.setId(documentId2); - sampleEntity2.setMessage("B.hello world."); + sampleEntity2.setMessage("world"); repository.save(sampleEntity2); //when Iterable sampleEntities=repository.findAll(new Sort(new Sort.Order(Sort.Direction.ASC,"message"))); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java index 093265fb6..53d08608b 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java @@ -373,13 +373,13 @@ public class SimpleElasticsearchRepositoryTests { String documentId = randomNumeric(5); SampleEntity sampleEntity = new SampleEntity(); sampleEntity.setId(documentId); - sampleEntity.setMessage("A. hello world."); + sampleEntity.setMessage("world"); repository.save(sampleEntity); String documentId2 = randomNumeric(5); SampleEntity sampleEntity2 = new SampleEntity(); sampleEntity2.setId(documentId2); - sampleEntity2.setMessage("B.hello world."); + sampleEntity2.setMessage("hello"); repository.save(sampleEntity2); //when Iterable sampleEntities=repository.findAll(new Sort(new Sort.Order(Sort.Direction.ASC,"message"))); diff --git a/src/test/resources/infrastructure.xml b/src/test/resources/infrastructure.xml index 20c173d08..0d98dc975 100644 --- a/src/test/resources/infrastructure.xml +++ b/src/test/resources/infrastructure.xml @@ -5,6 +5,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - + \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/elasticsearch/config/namespace.xml b/src/test/resources/org/springframework/data/elasticsearch/config/namespace.xml index dc1b7e70c..52d0d6d66 100644 --- a/src/test/resources/org/springframework/data/elasticsearch/config/namespace.xml +++ b/src/test/resources/org/springframework/data/elasticsearch/config/namespace.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - +