mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-23 20:42:11 +00:00
DATAES-71 - Enhance Create Index in ElasticsearchTemplate
added createIndex(String indexName) method
This commit is contained in:
parent
00eef9cb6c
commit
6a99d355c0
@ -45,6 +45,14 @@ public interface ElasticsearchOperations {
|
|||||||
*/
|
*/
|
||||||
<T> boolean createIndex(Class<T> clazz);
|
<T> boolean createIndex(Class<T> clazz);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an index for given indexName
|
||||||
|
*
|
||||||
|
* @param indexName
|
||||||
|
*/
|
||||||
|
boolean createIndex(String indexName);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create mapping for a class
|
* Create mapping for a class
|
||||||
*
|
*
|
||||||
|
@ -117,6 +117,14 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
|||||||
return createIndexIfNotCreated(clazz);
|
return createIndexIfNotCreated(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean createIndex(String indexName) {
|
||||||
|
Assert.notNull(indexName, "No index defined for Query");
|
||||||
|
return client.admin().indices()
|
||||||
|
.create(Requests.createIndexRequest(indexName))
|
||||||
|
.actionGet().isAcknowledged();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> boolean putMapping(Class<T> clazz) {
|
public <T> boolean putMapping(Class<T> clazz) {
|
||||||
ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz);
|
ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz);
|
||||||
|
@ -1256,6 +1256,23 @@ public class ElasticsearchTemplateTests {
|
|||||||
private void cleanUpIndices() {
|
private void cleanUpIndices() {
|
||||||
elasticsearchTemplate.deleteIndex("test-index-1");
|
elasticsearchTemplate.deleteIndex("test-index-1");
|
||||||
elasticsearchTemplate.deleteIndex("test-index-2");
|
elasticsearchTemplate.deleteIndex("test-index-2");
|
||||||
|
elasticsearchTemplate.createIndex("test-index-1");
|
||||||
|
elasticsearchTemplate.createIndex("test-index-2");
|
||||||
|
elasticsearchTemplate.refresh("test-index-1", true);
|
||||||
|
elasticsearchTemplate.refresh("test-index-2", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
DATAES-71
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldCreatedIndexWithSpecifiedIndexName() {
|
||||||
|
// given
|
||||||
|
elasticsearchTemplate.deleteIndex("test-index");
|
||||||
|
// when
|
||||||
|
elasticsearchTemplate.createIndex("test-index");
|
||||||
|
// then
|
||||||
|
assertThat(elasticsearchTemplate.indexExists("test-index"), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1263,7 +1280,7 @@ public class ElasticsearchTemplateTests {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldDeleteIndexForSpecifiedIndexName() {
|
public void shouldDeleteIndexForSpecifiedIndexName() {
|
||||||
//given
|
// given
|
||||||
elasticsearchTemplate.createIndex(SampleEntity.class);
|
elasticsearchTemplate.createIndex(SampleEntity.class);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class, true);
|
elasticsearchTemplate.refresh(SampleEntity.class, true);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user