DATAES-724 - Provide IndexOperations bean.

Original PR: #381
This commit is contained in:
Peter-Josef Meisch 2020-01-12 18:11:40 +01:00 committed by GitHub
parent 513741bcf6
commit e670a88772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 73 additions and 147 deletions

View File

@ -19,6 +19,7 @@ import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
/**
@ -47,4 +48,9 @@ public abstract class AbstractElasticsearchConfiguration extends ElasticsearchCo
public ElasticsearchOperations elasticsearchOperations(ElasticsearchConverter elasticsearchConverter) {
return new ElasticsearchRestTemplate(elasticsearchClient(), elasticsearchConverter);
}
@Bean
public IndexOperations indexOperations(ElasticsearchOperations elasticsearchOperations) {
return elasticsearchOperations.getIndexOperations();
}
}

View File

@ -68,11 +68,10 @@ import org.springframework.test.context.ContextConfiguration;
public class NestedObjectTests {
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, Book.class);
IndexInitializer.init(indexOperations, Person.class);
IndexInitializer.init(indexOperations, PersonMultipleLevelNested.class);
@ -388,8 +387,7 @@ public class NestedObjectTests {
@Setter
@Getter
@Document(indexName = "test-index-book-nested-objects", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-book-nested-objects", replicas = 0, refreshInterval = "-1")
static class Book {
@Id private String id;
@ -427,8 +425,7 @@ public class NestedObjectTests {
* @author Artur Konczak
*/
@Data
@Document(indexName = "test-index-person-multiple-level-nested", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-person-multiple-level-nested", replicas = 0, refreshInterval = "-1")
static class PersonMultipleLevelNested {
@Id private String id;

View File

@ -39,7 +39,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Score;
import org.springframework.data.elasticsearch.annotations.ScriptedField;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
@ -73,7 +73,7 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA
@EnableElasticsearchRepositories
static class Config {}
@Autowired ElasticsearchOperations operations;
@Autowired private IndexOperations indexOperations;
@Autowired private SampleElasticsearchRepository repository;
@ -83,7 +83,7 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA
@BeforeEach
public void before() {
IndexInitializer.init(operations.getIndexOperations(), SampleEntity.class);
IndexInitializer.init(indexOperations, SampleEntity.class);
}
@Test

View File

@ -111,14 +111,10 @@ public abstract class ElasticsearchTemplateTests {
protected final IndexCoordinates index = IndexCoordinates.of(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME);
@Autowired protected ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
deleteIndices();
indexOperations.createIndex(SampleEntity.class);

View File

@ -62,11 +62,10 @@ public class LogEntityTests {
private final IndexCoordinates index = IndexCoordinates.of("test-index-log-core").withTypes("test-log-type");
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() throws ParseException {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, LogEntity.class);
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");

View File

@ -77,11 +77,10 @@ public class ElasticsearchTemplateAggregationTests {
static final String INDEX_NAME = "test-index-articles-core-aggregation";
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, ArticleEntity.class);
IndexQuery article1 = new ArticleEntityBuilder("1").title("article four").subject("computing")
@ -120,7 +119,8 @@ public class ElasticsearchTemplateAggregationTests {
.addAggregation(terms("subjects").field("subject")) //
.build();
// when
SearchHits<ArticleEntity> searchHits = operations.search(searchQuery, ArticleEntity.class, IndexCoordinates.of(INDEX_NAME));
SearchHits<ArticleEntity> searchHits = operations.search(searchQuery, ArticleEntity.class,
IndexCoordinates.of(INDEX_NAME));
Aggregations aggregations = searchHits.getAggregations();
// then
@ -135,8 +135,7 @@ public class ElasticsearchTemplateAggregationTests {
* @author Mohsin Husen
*/
@Data
@Document(indexName = "test-index-articles-core-aggregation", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-articles-core-aggregation", replicas = 0, refreshInterval = "-1")
static class ArticleEntity {
@Id private String id;

View File

@ -62,13 +62,10 @@ public class ElasticsearchTemplateCompletionTests {
static class Config {}
@Autowired private ElasticsearchOperations operations;
IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
private void setup() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, CompletionEntity.class);
IndexInitializer.init(indexOperations, AnnotatedCompletionEntity.class);
}
@ -244,8 +241,7 @@ public class ElasticsearchTemplateCompletionTests {
/**
* @author Mewes Kochheim
*/
@Document(indexName = "test-index-core-completion", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-core-completion", replicas = 0, refreshInterval = "-1")
static class CompletionEntity {
@Id private String id;
@ -328,8 +324,7 @@ public class ElasticsearchTemplateCompletionTests {
/**
* @author Mewes Kochheim
*/
@Document(indexName = "test-index-annotated-completion", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-annotated-completion", replicas = 0, refreshInterval = "-1")
static class AnnotatedCompletionEntity {
@Id private String id;

View File

@ -66,12 +66,10 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
static class Config {}
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
void setup() {
indexOperations = operations.getIndexOperations();
indexOperations.deleteIndex(ContextCompletionEntity.class);
}
@ -243,8 +241,7 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
* @author Mewes Kochheim
* @author Robert Gruendler
*/
@Document(indexName = "test-index-context-completion", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-context-completion", replicas = 0, refreshInterval = "-1")
static class ContextCompletionEntity {
public static final String LANGUAGE_CATEGORY = "language";

View File

@ -78,14 +78,10 @@ public class ElasticsearchTemplateGeoTests {
.withTypes("geo-class-point-type");
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, AuthorMarkerEntity.class);
IndexInitializer.init(indexOperations, LocationMarkerEntity.class);
}
@ -375,8 +371,7 @@ public class ElasticsearchTemplateGeoTests {
* @author Mohsin Husen
*/
@Data
@Document(indexName = "test-index-author-marker-core-geo", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-author-marker-core-geo", replicas = 0, refreshInterval = "-1")
static class AuthorMarkerEntity {
@Id private String id;
@ -434,8 +429,7 @@ public class ElasticsearchTemplateGeoTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-location-marker-core-geo",
replicas = 0, refreshInterval = "-1")
@Document(indexName = "test-index-location-marker-core-geo", replicas = 0, refreshInterval = "-1")
static class LocationMarkerEntity {
@Id private String id;

View File

@ -28,7 +28,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.io.IOException;
import java.lang.Boolean;
import java.lang.Double;
import java.lang.Integer;
@ -84,13 +83,11 @@ import org.springframework.test.context.ContextConfiguration;
public class MappingBuilderTests extends MappingContextBaseTests {
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
indexOperations.deleteIndex(StockPrice.class);
indexOperations.deleteIndex(SimpleRecursiveEntity.class);
indexOperations.deleteIndex(StockPrice.class);
@ -113,8 +110,8 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@Test // DATAES-568
public void testInfiniteLoopAvoidance() throws JSONException {
String expected = "{\"properties\":{\"message\":{\"store\":true,\""
+ "type\":\"text\",\"index\":false," + "\"analyzer\":\"standard\"}}}";
String expected = "{\"properties\":{\"message\":{\"store\":true,\"" + "type\":\"text\",\"index\":false,"
+ "\"analyzer\":\"standard\"}}}";
String mapping = getMappingBuilder().buildPropertyMapping(SampleTransientEntity.class);
@ -319,8 +316,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
public void shouldUseFieldNameOnId() throws JSONException {
// given
String expected = "{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true}"
+ "}}";
String expected = "{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true}" + "}}";
// when
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.IdEntity.class);
@ -648,8 +644,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-book-mapping-builder", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-book-mapping-builder", replicas = 0, refreshInterval = "-1")
static class Book {
@Id private String id;
@ -665,8 +660,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
* @author Stuart Stevenson
* @author Mohsin Husen
*/
@Document(indexName = "test-index-simple-recursive-mapping-builder",
replicas = 0, refreshInterval = "-1")
@Document(indexName = "test-index-simple-recursive-mapping-builder", replicas = 0, refreshInterval = "-1")
static class SimpleRecursiveEntity {
@Id private String id;
@ -701,8 +695,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-normalizer-mapping-builder", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-normalizer-mapping-builder", replicas = 0, refreshInterval = "-1")
@Setting(settingPath = "/settings/test-normalizer.json")
static class NormalizerEntity {
@ -743,8 +736,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
/**
* @author Kevin Leturc
*/
@Document(indexName = "test-index-sample-inherited-mapping-builder", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-sample-inherited-mapping-builder", replicas = 0, refreshInterval = "-1")
static class SampleInheritedEntity extends AbstractInheritedEntity {
@Field(type = Text, index = false, store = true, analyzer = "standard") private String message;
@ -801,8 +793,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-stock-mapping-builder", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-stock-mapping-builder", replicas = 0, refreshInterval = "-1")
static class StockPrice {
@Id private String id;
@ -841,8 +832,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
/**
* @author Jakub Vavrik
*/
@Document(indexName = "test-index-recursive-mapping-mapping-builder", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-recursive-mapping-mapping-builder", replicas = 0, refreshInterval = "-1")
static class SampleTransientEntity {
@Id private String id;
@ -898,8 +888,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-geo-mapping-builder", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-geo-mapping-builder", replicas = 0, refreshInterval = "-1")
static class GeoEntity {
@Id private String id;

View File

@ -67,12 +67,10 @@ public class CriteriaQueryTests {
private final IndexCoordinates index = IndexCoordinates.of("test-index-sample-core-query").withTypes("test-type");
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
indexOperations.deleteIndex(SampleEntity.class);
indexOperations.createIndex(SampleEntity.class);
indexOperations.putMapping(SampleEntity.class);
@ -846,8 +844,7 @@ public class CriteriaQueryTests {
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "test-index-sample-core-query", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-sample-core-query", replicas = 0, refreshInterval = "-1")
static class SampleEntity {
@Id private String id;

View File

@ -19,7 +19,9 @@ import org.elasticsearch.client.Client;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.ElasticsearchConfigurationSupport;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
/**
@ -42,4 +44,8 @@ public class ElasticsearchTemplateConfiguration extends ElasticsearchConfigurati
return new ElasticsearchTemplate(elasticsearchClient, elasticsearchConverter);
}
@Bean
IndexOperations indexOperations(ElasticsearchOperations elasticsearchOperations) {
return elasticsearchOperations.getIndexOperations();
}
}

View File

@ -29,7 +29,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
@ -53,12 +52,10 @@ public class ComplexCustomMethodRepositoryTests {
@Autowired private ComplexElasticsearchRepository complexRepository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, SampleEntity.class);
}
@ -80,8 +77,8 @@ public class ComplexCustomMethodRepositoryTests {
}
@Data
@Document(indexName = "test-index-sample-repositories-complex-custommethod-autowiring",
replicas = 0, refreshInterval = "-1")
@Document(indexName = "test-index-sample-repositories-complex-custommethod-autowiring", replicas = 0,
refreshInterval = "-1")
static class SampleEntity {
@Id private String id;

View File

@ -29,7 +29,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
@ -52,12 +51,10 @@ public class ComplexCustomMethodRepositoryManualWiringTests {
@Autowired private ComplexElasticsearchRepositoryManualWiring complexRepository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, SampleEntity.class);
}
@ -79,8 +76,7 @@ public class ComplexCustomMethodRepositoryManualWiringTests {
}
@Data
@Document(indexName = "test-index-sample-repository-manual-wiring", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-sample-repository-manual-wiring", replicas = 0, refreshInterval = "-1")
static class SampleEntity {
@Id private String id;

View File

@ -49,7 +49,6 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
@ -80,12 +79,10 @@ public abstract class CustomMethodRepositoryBaseTests {
@Autowired private SampleStreamingCustomMethodRepository streamingRepository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, SampleEntity.class);
}

View File

@ -30,7 +30,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
@ -57,12 +56,10 @@ public class DoubleIDRepositoryTests {
@Autowired private DoubleIDRepository repository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, DoubleIDEntity.class);
}
@ -121,8 +118,7 @@ public class DoubleIDRepositoryTests {
* @author Mohsin Husen
*/
@Document(indexName = "test-index-double-keyed-entity", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-double-keyed-entity", replicas = 0, refreshInterval = "-1")
static class DoubleIDEntity {
@Id private Double id;

View File

@ -26,7 +26,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
@ -57,16 +56,12 @@ public class DynamicIndexEntityTests {
@Autowired private DynamicIndexRepository repository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@Autowired private IndexNameProvider indexNameProvider;
@BeforeEach
public void init() {
indexOperations = operations.getIndexOperations();
deleteIndexes();
indexOperations.createIndex("index1");
indexOperations.createIndex("index2");

View File

@ -35,7 +35,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
@ -63,15 +62,12 @@ public class SpringDataGeoRepositoryTests {
@EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
@Autowired ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@Autowired SpringDataGeoRepository repository;
@BeforeEach
public void init() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, GeoEntity.class);
}
@ -121,8 +117,7 @@ public class SpringDataGeoRepositoryTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-geo-repository", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-geo-repository", replicas = 0, refreshInterval = "-1")
static class GeoEntity {
@Id private String id;

View File

@ -30,7 +30,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
@ -57,12 +56,10 @@ public class IntegerIDRepositoryTests {
@Autowired private IntegerIDRepository repository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, IntegerIDEntity.class);
}
@ -121,8 +118,7 @@ public class IntegerIDRepositoryTests {
* @author Mohsin Husen
*/
@Document(indexName = "test-index-integer-keyed-entity", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-integer-keyed-entity", replicas = 0, refreshInterval = "-1")
static class IntegerIDEntity {
@Id private Integer id;

View File

@ -41,7 +41,6 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.InnerField;
import org.springframework.data.elasticsearch.annotations.MultiField;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
@ -66,12 +65,10 @@ public class InnerObjectTests {
@Autowired private SampleElasticSearchBookRepository bookRepository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, Book.class);
}

View File

@ -61,13 +61,12 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
static class Config {}
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@Autowired private DynamicSettingAndMappingEntityRepository repository;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, DynamicSettingAndMappingEntity.class);
}

View File

@ -52,15 +52,11 @@ public class FieldDynamicMappingEntityRepositoryTests {
@EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
@Autowired private FieldDynamicMappingEntityRepository repository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, FieldDynamicMappingEntity.class);
}

View File

@ -55,11 +55,10 @@ public class SpELEntityTests {
@Autowired private SpELRepository repository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, SpELEntity.class);
}
@ -103,8 +102,7 @@ public class SpELEntityTests {
*
* @author Artur Konczak
*/
@Document(indexName = "#{'test-index-abz'+'-'+'entity'}", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "#{'test-index-abz'+'-'+'entity'}", replicas = 0, refreshInterval = "-1")
static class SpELEntity {
@Id private String id;

View File

@ -60,11 +60,10 @@ public class SynonymRepositoryTests {
@Autowired private SynonymRepository repository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, SynonymEntity.class);
}

View File

@ -45,7 +45,6 @@ import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.ScriptedField;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
@ -77,12 +76,10 @@ public class UUIDElasticsearchRepositoryTests {
@Autowired private SampleUUIDKeyedElasticsearchRepository repository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, SampleEntityUUIDKeyed.class);
}

View File

@ -37,7 +37,6 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
@ -66,13 +65,10 @@ class QueryKeywordsTests {
@Autowired private ProductRepository repository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, Product.class);
Product product1 = Product.builder().id("1").name("Sugar").text("Cane sugar").price(1.0f).available(false)
@ -275,8 +271,7 @@ class QueryKeywordsTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-product-query-keywords", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-product-query-keywords", replicas = 0, refreshInterval = "-1")
static class Product {
@Id private String id;

View File

@ -81,11 +81,10 @@ public class SimpleElasticsearchRepositoryTests {
@Autowired private SampleElasticsearchRepository repository;
@Autowired private ElasticsearchOperations operations;
private IndexOperations indexOperations;
@Autowired private IndexOperations indexOperations;
@BeforeEach
public void before() {
indexOperations = operations.getIndexOperations();
IndexInitializer.init(indexOperations, SampleEntity.class);
}

View File

@ -36,11 +36,11 @@ public class IndexInitializer {
*/
@Deprecated
public static void init(ElasticsearchOperations operations, Class<?> clazz) {
operations.getIndexOperations().deleteIndex(clazz);
operations.getIndexOperations().createIndex(clazz);
operations.getIndexOperations().putMapping(clazz);
operations.getIndexOperations().refresh(clazz);
IndexOperations indexOperations = operations.getIndexOperations();
indexOperations.deleteIndex(clazz);
indexOperations.createIndex(clazz);
indexOperations.putMapping(clazz);
indexOperations.refresh(clazz);
}
/**
@ -50,7 +50,6 @@ public class IndexInitializer {
* @param clazz
*/
public static void init(IndexOperations operations, Class<?> clazz) {
operations.deleteIndex(clazz);
operations.createIndex(clazz);
operations.putMapping(clazz);