mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-31 09:12:11 +00:00
DATAES-826 - Add method to IndexOperations to write an index mapping from an entity class.
Original PR: #455
This commit is contained in:
parent
6487d0ddd4
commit
7540a2a1a8
@ -186,7 +186,7 @@ default boolean createIndex(String indexName) {
|
||||
@Deprecated
|
||||
default boolean putMapping(Class<?> clazz) {
|
||||
IndexOperations indexOps = indexOps(clazz);
|
||||
return indexOps.putMapping(indexOps.createMapping(clazz));
|
||||
return indexOps.putMapping(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,7 +202,7 @@ default boolean createIndex(String indexName) {
|
||||
@Deprecated
|
||||
default boolean putMapping(IndexCoordinates index, Class<?> clazz) {
|
||||
IndexOperations indexOps = indexOps(index);
|
||||
return indexOps.putMapping(indexOps.createMapping(clazz));
|
||||
return indexOps.putMapping(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,6 +93,16 @@ public interface IndexOperations {
|
||||
*/
|
||||
boolean putMapping(Document mapping);
|
||||
|
||||
/**
|
||||
* Creates the index mapping for the given class and writes it to the index.
|
||||
* @param clazz the clazz to create a mapping for
|
||||
* @return {@literal true} if the mapping could be stored
|
||||
* @since 4.1
|
||||
*/
|
||||
default boolean putMapping(Class<?> clazz) {
|
||||
return putMapping(createMapping(clazz));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mapping for an index defined by a class.
|
||||
*
|
||||
|
@ -102,7 +102,7 @@ public abstract class AbstractElasticsearchRepository<T, ID> implements Elastics
|
||||
}
|
||||
|
||||
private void putMapping() {
|
||||
indexOperations.putMapping(indexOperations.createMapping(entityClass));
|
||||
indexOperations.putMapping(entityClass);
|
||||
}
|
||||
|
||||
private boolean createIndexAndMapping() {
|
||||
|
@ -123,15 +123,15 @@ public abstract class ElasticsearchTemplateTests {
|
||||
deleteIndices();
|
||||
|
||||
indexOperations.create();
|
||||
indexOperations.putMapping(indexOperations.createMapping(SampleEntity.class));
|
||||
indexOperations.putMapping(SampleEntity.class);
|
||||
|
||||
IndexOperations indexOpsSampleEntityUUIDKeyed = operations.indexOps(SampleEntityUUIDKeyed.class);
|
||||
indexOpsSampleEntityUUIDKeyed.create();
|
||||
indexOpsSampleEntityUUIDKeyed.putMapping(indexOpsSampleEntityUUIDKeyed.createMapping(SampleEntityUUIDKeyed.class));
|
||||
indexOpsSampleEntityUUIDKeyed.putMapping(SampleEntityUUIDKeyed.class);
|
||||
|
||||
IndexOperations indexOpsSearchHitsEntity = operations.indexOps(SearchHitsEntity.class);
|
||||
indexOpsSearchHitsEntity.create();
|
||||
indexOpsSearchHitsEntity.putMapping(indexOpsSearchHitsEntity.createMapping(SearchHitsEntity.class));
|
||||
indexOpsSearchHitsEntity.putMapping(SearchHitsEntity.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@ -1419,7 +1419,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
// when
|
||||
|
||||
// then
|
||||
assertThat(indexOperations.putMapping(indexOperations.createMapping(entityClass))).isTrue();
|
||||
assertThat(indexOperations.putMapping(entityClass)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAES-305
|
||||
@ -1432,7 +1432,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
indexOperations1.create();
|
||||
|
||||
// when
|
||||
indexOperations1.putMapping(indexOperations1.createMapping(entity));
|
||||
indexOperations1.putMapping(entity);
|
||||
|
||||
// then
|
||||
Map<String, Object> mapping = indexOperations.getMapping();
|
||||
@ -1622,7 +1622,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
IndexOperations bookIndexOperations = operations.indexOps(Book.class);
|
||||
bookIndexOperations.delete();
|
||||
bookIndexOperations.create();
|
||||
indexOperations.putMapping(indexOperations.createMapping(clazz));
|
||||
indexOperations.putMapping(clazz);
|
||||
bookIndexOperations.refresh();
|
||||
|
||||
IndexCoordinates bookIndex = IndexCoordinates.of("test-index-book-core-template").withTypes("book");
|
||||
@ -2263,7 +2263,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
// when
|
||||
indexOperations.delete();
|
||||
indexOperations.create(parse(settings));
|
||||
indexOperations.putMapping(indexOperations.createMapping(SampleEntity.class));
|
||||
indexOperations.putMapping(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
|
||||
// then
|
||||
|
@ -108,7 +108,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
deleteIndices();
|
||||
|
||||
indexOperations.create();
|
||||
indexOperations.putMapping(indexOperations.createMapping(SampleEntity.class));
|
||||
indexOperations.putMapping(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
|
||||
template = new ReactiveElasticsearchTemplate(TestUtils.reactiveClient(), restTemplate.getElasticsearchConverter());
|
||||
|
@ -55,7 +55,7 @@ abstract class ElasticsearchOperationsCallbackTest {
|
||||
IndexOperations indexOps = operations.indexOps(SampleEntity.class);
|
||||
indexOps.delete();
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(SampleEntity.class));
|
||||
indexOps.putMapping(SampleEntity.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
@ -67,7 +67,7 @@ public class ReactiveElasticsearchOperationsCallbackTest {
|
||||
void setUp() {
|
||||
IndexOperations indexOps = nonreactiveOperations.indexOps(SampleEntity.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(SampleEntity.class));
|
||||
indexOps.putMapping(SampleEntity.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
@ -108,7 +108,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
public void shouldNotFailOnCircularReference() {
|
||||
|
||||
operations.indexOps(SimpleRecursiveEntity.class).create();
|
||||
indexOperations.putMapping(indexOperations.createMapping(SimpleRecursiveEntity.class));
|
||||
indexOperations.putMapping(SimpleRecursiveEntity.class);
|
||||
indexOperations.refresh();
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
|
||||
// When
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(StockPrice.class));
|
||||
indexOps.putMapping(StockPrice.class);
|
||||
String symbol = "AU";
|
||||
double price = 2.34;
|
||||
String id = "abc";
|
||||
@ -197,7 +197,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
|
||||
// when
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(SampleInheritedEntity.class));
|
||||
indexOps.putMapping(SampleInheritedEntity.class);
|
||||
Date createdDate = new Date();
|
||||
String message = "msg";
|
||||
String id = "abc";
|
||||
@ -238,11 +238,11 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
// given
|
||||
IndexOperations indexOpsUser = operations.indexOps(User.class);
|
||||
indexOpsUser.create();
|
||||
indexOpsUser.putMapping(indexOpsUser.createMapping(User.class));
|
||||
indexOpsUser.putMapping(User.class);
|
||||
|
||||
IndexOperations indexOpsGroup = operations.indexOps(Group.class);
|
||||
indexOpsGroup.create();
|
||||
indexOpsGroup.putMapping(indexOpsGroup.createMapping(Group.class));
|
||||
indexOpsGroup.putMapping(Group.class);
|
||||
|
||||
// when
|
||||
|
||||
@ -255,7 +255,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
// given
|
||||
IndexOperations indexOps = operations.indexOps(Book.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(Book.class));
|
||||
indexOps.putMapping(Book.class);
|
||||
|
||||
// when
|
||||
|
||||
@ -268,7 +268,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
// given
|
||||
IndexOperations indexOps = this.operations.indexOps(Book.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(Book.class));
|
||||
indexOps.putMapping(Book.class);
|
||||
|
||||
// when
|
||||
Map mapping = indexOps.getMapping();
|
||||
@ -310,7 +310,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
// given
|
||||
IndexOperations indexOps = operations.indexOps(CopyToEntity.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(CopyToEntity.class));
|
||||
indexOps.putMapping(CopyToEntity.class);
|
||||
|
||||
// when
|
||||
Map mapping = indexOps.getMapping();
|
||||
|
@ -74,7 +74,7 @@ public class CriteriaQueryTests {
|
||||
indexOperations = operations.indexOps(SampleEntity.class);
|
||||
indexOperations.delete();
|
||||
indexOperations.create();
|
||||
indexOperations.putMapping(indexOperations.createMapping(SampleEntity.class));
|
||||
indexOperations.putMapping(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user