committed by
GitHub
parent
1f56a9b9fe
commit
96ebc72dd1
@@ -30,6 +30,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
@@ -44,10 +45,8 @@ 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.core.SearchHits;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
@@ -68,13 +67,12 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
public class NestedObjectTests {
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, Book.class);
|
||||
IndexInitializer.init(indexOperations, Person.class);
|
||||
IndexInitializer.init(indexOperations, PersonMultipleLevelNested.class);
|
||||
IndexInitializer.init(operations.indexOps(Book.class));
|
||||
IndexInitializer.init(operations.indexOps(Person.class));
|
||||
IndexInitializer.init(operations.indexOps(PersonMultipleLevelNested.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +124,7 @@ public class NestedObjectTests {
|
||||
|
||||
IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes("user");
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(Person.class);
|
||||
operations.indexOps(Person.class).refresh();
|
||||
|
||||
QueryBuilder builder = nestedQuery("car",
|
||||
boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")), ScoreMode.None);
|
||||
@@ -146,11 +144,10 @@ public class NestedObjectTests {
|
||||
// when
|
||||
operations.bulkIndex(indexQueries,
|
||||
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
|
||||
indexOperations.refresh(PersonMultipleLevelNested.class);
|
||||
operations.indexOps(PersonMultipleLevelNested.class).refresh();
|
||||
|
||||
// then
|
||||
GetQuery getQuery = new GetQuery("1");
|
||||
PersonMultipleLevelNested personIndexed = operations.get(getQuery, PersonMultipleLevelNested.class,
|
||||
PersonMultipleLevelNested personIndexed = operations.get("1", PersonMultipleLevelNested.class,
|
||||
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
|
||||
assertThat(personIndexed).isNotNull();
|
||||
}
|
||||
@@ -166,7 +163,7 @@ public class NestedObjectTests {
|
||||
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
|
||||
|
||||
// then
|
||||
Map<String, Object> mapping = indexOperations.getMapping(PersonMultipleLevelNested.class);
|
||||
Map<String, Object> mapping = operations.indexOps(PersonMultipleLevelNested.class).getMapping();
|
||||
|
||||
assertThat(mapping).isNotNull();
|
||||
Map<String, Object> propertyMap = (Map<String, Object>) mapping.get("properties");
|
||||
@@ -184,7 +181,7 @@ public class NestedObjectTests {
|
||||
// when
|
||||
IndexCoordinates index = IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user");
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(PersonMultipleLevelNested.class);
|
||||
operations.indexOps(PersonMultipleLevelNested.class).refresh();
|
||||
|
||||
// then
|
||||
BoolQueryBuilder builder = boolQuery();
|
||||
@@ -324,7 +321,7 @@ public class NestedObjectTests {
|
||||
|
||||
IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes("user");
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(Person.class);
|
||||
operations.indexOps(Person.class).refresh();
|
||||
|
||||
// when
|
||||
QueryBuilder builder = nestedQuery("books", boolQuery().must(termQuery("books.name", "java")), ScoreMode.None);
|
||||
@@ -373,7 +370,7 @@ public class NestedObjectTests {
|
||||
// when
|
||||
IndexCoordinates index = IndexCoordinates.of("test-index-book-nested-objects").withTypes("book");
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(Book.class);
|
||||
operations.indexOps(Book.class).refresh();
|
||||
|
||||
// then
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
|
||||
@@ -39,6 +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;
|
||||
@@ -74,17 +75,19 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA
|
||||
@EnableElasticsearchRepositories
|
||||
static class Config {}
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@Autowired private SampleElasticsearchRepository repository;
|
||||
|
||||
@Autowired(required = false) private SampleRepository nestedRepository;
|
||||
|
||||
interface SampleRepository extends Repository<EnableElasticsearchRepositoriesTests.SampleEntity, Long> {}
|
||||
interface SampleRepository extends Repository<SampleEntity, Long> {}
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, SampleEntity.class);
|
||||
indexOperations = operations.indexOps(SampleEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,14 +23,11 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import org.elasticsearch.ElasticsearchStatusException;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
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.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -57,16 +54,15 @@ public class ElasticsearchRestTemplateTests extends ElasticsearchTemplateTests {
|
||||
public void shouldThrowExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
|
||||
|
||||
// when
|
||||
IndexRequest indexRequest = new IndexRequest();
|
||||
indexRequest.source("{}", XContentType.JSON);
|
||||
UpdateQuery updateQuery = new UpdateQueryBuilder().withId(randomNumeric(5)).withIndexRequest(indexRequest).build();
|
||||
org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document
|
||||
.create();
|
||||
UpdateQuery updateQuery = UpdateQuery.builder(randomNumeric(5)).withDocument(document).build();
|
||||
assertThatThrownBy(() -> operations.update(updateQuery, index)).isInstanceOf(ElasticsearchStatusException.class);
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Document(indexName = "test-index-sample-core-rest-template", replicas = 0,
|
||||
refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-sample-core-rest-template", replicas = 0, refreshInterval = "-1")
|
||||
static class SampleEntity {
|
||||
|
||||
@Id private String id;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,10 +21,8 @@ import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.engine.DocumentMissingException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -38,7 +36,6 @@ import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -56,9 +53,9 @@ public class ElasticsearchTransportTemplateTests extends ElasticsearchTemplateTe
|
||||
@Test
|
||||
public void shouldThrowExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
|
||||
// when
|
||||
IndexRequest indexRequest = new IndexRequest();
|
||||
indexRequest.source("{}", XContentType.JSON);
|
||||
UpdateQuery updateQuery = new UpdateQueryBuilder().withId(randomNumeric(5)).withIndexRequest(indexRequest).build();
|
||||
org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document
|
||||
.create();
|
||||
UpdateQuery updateQuery = UpdateQuery.builder(randomNumeric(5)).withDocument(document).build();
|
||||
assertThatThrownBy(() -> operations.update(updateQuery, index)).isInstanceOf(DocumentMissingException.class);
|
||||
}
|
||||
|
||||
@@ -87,8 +84,7 @@ public class ElasticsearchTransportTemplateTests extends ElasticsearchTemplateTe
|
||||
}
|
||||
|
||||
@Data
|
||||
@Document(indexName = "test-index-sample-core-transport-template", replicas = 0,
|
||||
refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-sample-core-transport-template", replicas = 0, refreshInterval = "-1")
|
||||
static class SampleEntity {
|
||||
|
||||
@Id private String id;
|
||||
|
||||
@@ -62,11 +62,12 @@ public class LogEntityTests {
|
||||
|
||||
private final IndexCoordinates index = IndexCoordinates.of("test-index-log-core").withTypes("test-log-type");
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() throws ParseException {
|
||||
IndexInitializer.init(indexOperations, LogEntity.class);
|
||||
indexOperations = operations.indexOps(LogEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
IndexQuery indexQuery1 = new LogEntityBuilder("1").action("update").date(dateFormatter.parse("2013-10-18 18:01"))
|
||||
@@ -82,12 +83,12 @@ public class LogEntityTests {
|
||||
.code(2).ip("10.10.10.4").buildIndex();
|
||||
|
||||
operations.bulkIndex(Arrays.asList(indexQuery1, indexQuery2, indexQuery3, indexQuery4), index);
|
||||
indexOperations.refresh(LogEntity.class);
|
||||
indexOperations.refresh();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(LogEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test // DATAES-66
|
||||
|
||||
@@ -40,7 +40,6 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.elasticsearch.ElasticsearchStatusException;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -66,7 +65,6 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.junit.junit4.ElasticsearchVersion;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -89,16 +87,18 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
|
||||
private ElasticsearchRestTemplate restTemplate;
|
||||
private ReactiveElasticsearchTemplate template;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
restTemplate = new ElasticsearchRestTemplate(TestUtils.restHighLevelClient());
|
||||
indexOperations = restTemplate.indexOps(SampleEntity.class);
|
||||
|
||||
deleteIndices();
|
||||
|
||||
restTemplate = new ElasticsearchRestTemplate(TestUtils.restHighLevelClient());
|
||||
restTemplate.createIndex(SampleEntity.class);
|
||||
restTemplate.putMapping(SampleEntity.class);
|
||||
restTemplate.refresh(SampleEntity.class);
|
||||
indexOperations.create();
|
||||
indexOperations.putMapping(indexOperations.createMapping(SampleEntity.class));
|
||||
indexOperations.refresh();
|
||||
|
||||
template = new ReactiveElasticsearchTemplate(TestUtils.reactiveClient(), restTemplate.getElasticsearchConverter());
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
.expectNextCount(1)//
|
||||
.verifyComplete();
|
||||
|
||||
restTemplate.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
|
||||
SearchHits<SampleEntity> result = restTemplate.search(
|
||||
new CriteriaQuery(Criteria.where("message").is(sampleEntity.getMessage())), SampleEntity.class,
|
||||
@@ -161,7 +161,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
|
||||
assertThat(it.getId()).isNotNull();
|
||||
|
||||
restTemplate.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
assertThat(TestUtils.documentWithId(it.getId()).existsIn(DEFAULT_INDEX)).isTrue();
|
||||
}) //
|
||||
.verifyComplete();
|
||||
@@ -205,27 +205,27 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void findByIdShouldCompleteWhenIndexDoesNotExist() {
|
||||
public void getByIdShouldCompleteWhenIndexDoesNotExist() {
|
||||
|
||||
template.findById("foo", SampleEntity.class, IndexCoordinates.of("no-such-index").withTypes("test-type")) //
|
||||
template.get("foo", SampleEntity.class, IndexCoordinates.of("no-such-index").withTypes("test-type")) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
public void findByIdShouldReturnEntity() {
|
||||
public void getByIdShouldReturnEntity() {
|
||||
|
||||
SampleEntity sampleEntity = randomEntity("some message");
|
||||
index(sampleEntity);
|
||||
|
||||
template.findById(sampleEntity.getId(), SampleEntity.class) //
|
||||
template.get(sampleEntity.getId(), SampleEntity.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(sampleEntity) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
public void findByIdWhenIdIsAutogeneratedShouldHaveIdSetCorrectly() {
|
||||
public void getByIdWhenIdIsAutogeneratedShouldHaveIdSetCorrectly() {
|
||||
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setMessage("some message");
|
||||
@@ -234,32 +234,32 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
|
||||
assertThat(sampleEntity.getId()).isNotNull();
|
||||
|
||||
template.findById(sampleEntity.getId(), SampleEntity.class) //
|
||||
template.get(sampleEntity.getId(), SampleEntity.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo(sampleEntity.getId())) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
public void findByIdShouldCompleteWhenNotingFound() {
|
||||
public void getByIdShouldCompleteWhenNotingFound() {
|
||||
|
||||
SampleEntity sampleEntity = randomEntity("some message");
|
||||
index(sampleEntity);
|
||||
|
||||
template.findById("foo", SampleEntity.class) //
|
||||
template.get("foo", SampleEntity.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
public void findByIdShouldErrorForNullId() {
|
||||
public void getByIdShouldErrorForNullId() {
|
||||
assertThatThrownBy(() -> {
|
||||
template.findById(null, SampleEntity.class);
|
||||
template.get(null, SampleEntity.class);
|
||||
}).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
public void findByIdWithExplicitIndexNameShouldOverwriteMetadata() {
|
||||
public void getByIdWithExplicitIndexNameShouldOverwriteMetadata() {
|
||||
|
||||
SampleEntity sampleEntity = randomEntity("some message");
|
||||
|
||||
@@ -269,16 +269,16 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
IndexCoordinates alternateIndex = IndexCoordinates.of(ALTERNATE_INDEX).withTypes("test-type");
|
||||
|
||||
restTemplate.index(indexQuery, alternateIndex);
|
||||
restTemplate.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
|
||||
restTemplate.refresh(defaultIndex);
|
||||
restTemplate.refresh(alternateIndex);
|
||||
restTemplate.indexOps(defaultIndex).refresh();
|
||||
restTemplate.indexOps(alternateIndex).refresh();
|
||||
|
||||
template.findById(sampleEntity.getId(), SampleEntity.class, defaultIndex) //
|
||||
template.get(sampleEntity.getId(), SampleEntity.class, defaultIndex) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
template.findById(sampleEntity.getId(), SampleEntity.class, alternateIndex) //
|
||||
template.get(sampleEntity.getId(), SampleEntity.class, alternateIndex) //
|
||||
.as(StepVerifier::create)//
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
@@ -520,20 +520,20 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void deleteByIdShouldCompleteWhenIndexDoesNotExist() {
|
||||
public void deleteShouldCompleteWhenIndexDoesNotExist() {
|
||||
|
||||
template.deleteById("does-not-exists", SampleEntity.class, IndexCoordinates.of("no-such-index")) //
|
||||
template.delete("does-not-exists", IndexCoordinates.of("no-such-index")) //
|
||||
.as(StepVerifier::create)//
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
public void deleteByIdShouldRemoveExistingDocumentById() {
|
||||
public void deleteShouldRemoveExistingDocumentById() {
|
||||
|
||||
SampleEntity sampleEntity = randomEntity("test message");
|
||||
index(sampleEntity);
|
||||
|
||||
template.deleteById(sampleEntity.getId(), SampleEntity.class) //
|
||||
template.delete(sampleEntity.getId(), SampleEntity.class) //
|
||||
.as(StepVerifier::create)//
|
||||
.expectNext(sampleEntity.getId()) //
|
||||
.verifyComplete();
|
||||
@@ -545,7 +545,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
SampleEntity sampleEntity = randomEntity("test message");
|
||||
index(sampleEntity);
|
||||
|
||||
template.deleteById(sampleEntity.getId(), IndexCoordinates.of(DEFAULT_INDEX).withTypes("test-type")) //
|
||||
template.delete(sampleEntity.getId(), IndexCoordinates.of(DEFAULT_INDEX).withTypes("test-type")) //
|
||||
.as(StepVerifier::create)//
|
||||
.expectNext(sampleEntity.getId()) //
|
||||
.verifyComplete();
|
||||
@@ -564,7 +564,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
public void deleteByIdShouldCompleteWhenNothingDeleted() {
|
||||
public void deleteShouldCompleteWhenNothingDeleted() {
|
||||
|
||||
SampleEntity sampleEntity = randomEntity("test message");
|
||||
|
||||
@@ -579,7 +579,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
|
||||
CriteriaQuery query = new CriteriaQuery(new Criteria("message").contains("test"));
|
||||
|
||||
template.deleteBy(query, SampleEntity.class) //
|
||||
template.delete(query, SampleEntity.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(0L) //
|
||||
.verifyComplete();
|
||||
@@ -606,7 +606,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
.withQuery(termQuery("message", "test")) //
|
||||
.build();
|
||||
|
||||
template.deleteBy(searchQuery, SampleEntity.class, IndexCoordinates.of(indexPrefix + '*')) //
|
||||
template.delete(searchQuery, SampleEntity.class, IndexCoordinates.of(indexPrefix + '*')) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(2L) //
|
||||
.verifyComplete();
|
||||
@@ -635,7 +635,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
.withQuery(termQuery("message", "negative")) //
|
||||
.build();
|
||||
|
||||
template.deleteBy(searchQuery, SampleEntity.class, IndexCoordinates.of(indexPrefix + '*')) //
|
||||
template.delete(searchQuery, SampleEntity.class, IndexCoordinates.of(indexPrefix + '*')) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(0L) //
|
||||
.verifyComplete();
|
||||
@@ -651,7 +651,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
|
||||
CriteriaQuery query = new CriteriaQuery(new Criteria("message").contains("test"));
|
||||
|
||||
template.deleteBy(query, SampleEntity.class) //
|
||||
template.delete(query, SampleEntity.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(2L) //
|
||||
.verifyComplete();
|
||||
@@ -665,7 +665,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
|
||||
CriteriaQuery query = new CriteriaQuery(new Criteria("message").contains("luke"));
|
||||
|
||||
template.deleteBy(query, SampleEntity.class) //
|
||||
template.delete(query, SampleEntity.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(0L) //
|
||||
.verifyComplete();
|
||||
@@ -763,17 +763,19 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
entity2.rate = 2;
|
||||
index(entity2);
|
||||
|
||||
IndexRequest indexRequest1 = new IndexRequest();
|
||||
indexRequest1.source("message", "updated 1");
|
||||
UpdateQuery updateQuery1 = new UpdateQueryBuilder() //
|
||||
.withId(entity1.getId()) //
|
||||
.withIndexRequest(indexRequest1).build();
|
||||
org.springframework.data.elasticsearch.core.document.Document document1 = org.springframework.data.elasticsearch.core.document.Document
|
||||
.create();
|
||||
document1.put("message", "updated 1");
|
||||
UpdateQuery updateQuery1 = UpdateQuery.builder(entity1.getId()) //
|
||||
.withDocument(document1) //
|
||||
.build();
|
||||
|
||||
IndexRequest indexRequest2 = new IndexRequest();
|
||||
indexRequest2.source("message", "updated 2");
|
||||
UpdateQuery updateQuery2 = new UpdateQueryBuilder() //
|
||||
.withId(entity2.getId()) //
|
||||
.withIndexRequest(indexRequest2).build();
|
||||
org.springframework.data.elasticsearch.core.document.Document document2 = org.springframework.data.elasticsearch.core.document.Document
|
||||
.create();
|
||||
document2.put("message", "updated 2");
|
||||
UpdateQuery updateQuery2 = UpdateQuery.builder(entity2.getId()) //
|
||||
.withDocument(document2) //
|
||||
.build();
|
||||
|
||||
List<UpdateQuery> queries = Arrays.asList(updateQuery1, updateQuery2);
|
||||
template.bulkUpdate(queries, IndexCoordinates.of(DEFAULT_INDEX)).block();
|
||||
@@ -858,7 +860,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
restTemplate.bulkIndex(getIndexQueries(entities), indexCoordinates);
|
||||
}
|
||||
|
||||
restTemplate.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -170,7 +170,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
||||
ArgumentCaptor<DeleteRequest> captor = ArgumentCaptor.forClass(DeleteRequest.class);
|
||||
when(client.delete(captor.capture())).thenReturn(Mono.empty());
|
||||
|
||||
template.deleteById("id", index) //
|
||||
template.delete("id", index) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
@@ -185,7 +185,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
||||
|
||||
template.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
|
||||
|
||||
template.deleteById("id", index) //
|
||||
template.delete("id", index) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
@@ -198,7 +198,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
||||
ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
|
||||
when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
|
||||
|
||||
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||
template.delete(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
@@ -213,7 +213,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
||||
|
||||
template.setRefreshPolicy(RefreshPolicy.NONE);
|
||||
|
||||
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||
template.delete(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
@@ -226,7 +226,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
||||
ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
|
||||
when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
|
||||
|
||||
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||
template.delete(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
@@ -241,7 +241,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
||||
|
||||
template.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
|
||||
|
||||
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||
template.delete(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
|
||||
@@ -77,11 +77,12 @@ public class ElasticsearchTemplateAggregationTests {
|
||||
static final String INDEX_NAME = "test-index-articles-core-aggregation";
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, ArticleEntity.class);
|
||||
indexOperations = operations.indexOps(ArticleEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
|
||||
IndexQuery article1 = new ArticleEntityBuilder("1").title("article four").subject("computing")
|
||||
.addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addAuthor(JONATHAN_YAN).score(10)
|
||||
@@ -101,12 +102,12 @@ public class ElasticsearchTemplateAggregationTests {
|
||||
operations.index(article2, index);
|
||||
operations.index(article3, index);
|
||||
operations.index(article4, index);
|
||||
operations.refresh(ArticleEntity.class);
|
||||
indexOperations.refresh();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void after() {
|
||||
indexOperations.deleteIndex(ArticleEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.springframework.data.elasticsearch.annotations.CompletionField;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||
@@ -63,18 +62,17 @@ public class ElasticsearchTemplateCompletionTests {
|
||||
static class Config {}
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
private void setup() {
|
||||
IndexInitializer.init(indexOperations, CompletionEntity.class);
|
||||
IndexInitializer.init(indexOperations, AnnotatedCompletionEntity.class);
|
||||
IndexInitializer.init(operations.indexOps(CompletionEntity.class));
|
||||
IndexInitializer.init(operations.indexOps(AnnotatedCompletionEntity.class));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex("test-index-annotated-completion");
|
||||
indexOperations.deleteIndex("test-index-core-completion");
|
||||
operations.indexOps(CompletionEntity.class).delete();
|
||||
operations.indexOps(AnnotatedCompletionEntity.class).delete();
|
||||
}
|
||||
|
||||
private void loadCompletionObjectEntities() {
|
||||
@@ -90,7 +88,7 @@ public class ElasticsearchTemplateCompletionTests {
|
||||
.buildIndex());
|
||||
|
||||
operations.bulkIndex(indexQueries, IndexCoordinates.of("test-index-core-completion").withTypes("completion-type"));
|
||||
operations.refresh(CompletionEntity.class);
|
||||
operations.indexOps(CompletionEntity.class).refresh();
|
||||
}
|
||||
|
||||
private void loadAnnotatedCompletionObjectEntities() {
|
||||
@@ -111,7 +109,7 @@ public class ElasticsearchTemplateCompletionTests {
|
||||
|
||||
operations.bulkIndex(indexQueries,
|
||||
IndexCoordinates.of("test-index-annotated-completion").withTypes("annotated-completion-type"));
|
||||
operations.refresh(AnnotatedCompletionEntity.class);
|
||||
operations.indexOps(AnnotatedCompletionEntity.class).refresh();
|
||||
}
|
||||
|
||||
private void loadAnnotatedCompletionObjectEntitiesWithWeights() {
|
||||
@@ -128,7 +126,7 @@ public class ElasticsearchTemplateCompletionTests {
|
||||
|
||||
operations.bulkIndex(indexQueries,
|
||||
IndexCoordinates.of("test-index-annotated-completion").withTypes("annotated-completion-type"));
|
||||
operations.refresh(AnnotatedCompletionEntity.class);
|
||||
operations.indexOps(AnnotatedCompletionEntity.class).refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -67,21 +67,22 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
|
||||
static class Config {}
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
indexOperations.deleteIndex(ContextCompletionEntity.class);
|
||||
indexOperations = operations.indexOps(ContextCompletionEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(ContextCompletionEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
private void loadContextCompletionObjectEntities() {
|
||||
|
||||
IndexInitializer.init(indexOperations, ContextCompletionEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
|
||||
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
|
||||
nonDocumentEntity.setSomeField1("foo");
|
||||
@@ -111,7 +112,7 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
|
||||
|
||||
operations.bulkIndex(indexQueries,
|
||||
IndexCoordinates.of("test-index-context-completion").withTypes("context-completion-type"));
|
||||
operations.refresh(ContextCompletionEntity.class);
|
||||
operations.indexOps(ContextCompletionEntity.class).refresh();
|
||||
}
|
||||
|
||||
@Test // DATAES-536
|
||||
|
||||
@@ -39,7 +39,6 @@ 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.SearchHit;
|
||||
import org.springframework.data.elasticsearch.core.SearchHits;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
@@ -78,18 +77,17 @@ public class ElasticsearchTemplateGeoTests {
|
||||
.withTypes("geo-class-point-type");
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, AuthorMarkerEntity.class);
|
||||
IndexInitializer.init(indexOperations, LocationMarkerEntity.class);
|
||||
IndexInitializer.init(operations.indexOps(AuthorMarkerEntity.class));
|
||||
IndexInitializer.init(operations.indexOps(LocationMarkerEntity.class));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(AuthorMarkerEntity.class);
|
||||
indexOperations.deleteIndex(LocationMarkerEntity.class);
|
||||
operations.indexOps(AuthorMarkerEntity.class).delete();
|
||||
operations.indexOps(LocationMarkerEntity.class).delete();
|
||||
}
|
||||
|
||||
private void loadClassBaseEntities() {
|
||||
@@ -100,7 +98,7 @@ public class ElasticsearchTemplateGeoTests {
|
||||
indexQueries.add(new AuthorMarkerEntityBuilder("2").name("Mohsin Husen").location(51.5171d, 0.1062d).buildIndex());
|
||||
indexQueries.add(new AuthorMarkerEntityBuilder("3").name("Rizwan Idrees").location(51.5171d, 0.1062d).buildIndex());
|
||||
operations.bulkIndex(indexQueries, authorMarkerIndex);
|
||||
operations.refresh(AuthorMarkerEntity.class);
|
||||
operations.indexOps(AuthorMarkerEntity.class).refresh();
|
||||
}
|
||||
|
||||
private void loadAnnotationBaseEntities() {
|
||||
@@ -132,7 +130,7 @@ public class ElasticsearchTemplateGeoTests {
|
||||
indexQueries.add(buildIndex(location3));
|
||||
|
||||
operations.bulkIndex(indexQueries, locationMarkerIndex);
|
||||
operations.refresh(LocationMarkerEntity.class);
|
||||
operations.indexOps(LocationMarkerEntity.class).refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -84,28 +84,27 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
|
||||
indexOperations.deleteIndex(StockPrice.class);
|
||||
indexOperations.deleteIndex(SimpleRecursiveEntity.class);
|
||||
indexOperations.deleteIndex(StockPrice.class);
|
||||
indexOperations.deleteIndex(SampleInheritedEntity.class);
|
||||
indexOperations.deleteIndex(User.class);
|
||||
indexOperations.deleteIndex(Group.class);
|
||||
indexOperations.deleteIndex(Book.class);
|
||||
indexOperations.deleteIndex(NormalizerEntity.class);
|
||||
indexOperations.deleteIndex(CopyToEntity.class);
|
||||
indexOperations = operations.indexOps(SimpleRecursiveEntity.class);
|
||||
indexOperations.delete();
|
||||
operations.indexOps(StockPrice.class).delete();
|
||||
operations.indexOps(SampleInheritedEntity.class).delete();
|
||||
operations.indexOps(User.class).delete();
|
||||
operations.indexOps(Group.class).delete();
|
||||
operations.indexOps(Book.class).delete();
|
||||
operations.indexOps(NormalizerEntity.class).delete();
|
||||
operations.indexOps(CopyToEntity.class).delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotFailOnCircularReference() {
|
||||
|
||||
indexOperations.createIndex(SimpleRecursiveEntity.class);
|
||||
indexOperations.putMapping(SimpleRecursiveEntity.class);
|
||||
indexOperations.refresh(SimpleRecursiveEntity.class);
|
||||
operations.indexOps(SimpleRecursiveEntity.class).create();
|
||||
indexOperations.putMapping(indexOperations.createMapping(SimpleRecursiveEntity.class));
|
||||
indexOperations.refresh();
|
||||
}
|
||||
|
||||
@Test // DATAES-568
|
||||
@@ -136,10 +135,11 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
public void shouldAddStockPriceDocumentToIndex() {
|
||||
|
||||
// Given
|
||||
IndexOperations indexOps = operations.indexOps(StockPrice.class);
|
||||
|
||||
// When
|
||||
indexOperations.createIndex(StockPrice.class);
|
||||
indexOperations.putMapping(StockPrice.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(StockPrice.class));
|
||||
String symbol = "AU";
|
||||
double price = 2.34;
|
||||
String id = "abc";
|
||||
@@ -150,7 +150,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
.symbol(symbol) //
|
||||
.price(BigDecimal.valueOf(price)) //
|
||||
.build()), index);
|
||||
indexOperations.refresh(StockPrice.class);
|
||||
operations.indexOps(StockPrice.class).refresh();
|
||||
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
SearchHits<StockPrice> result = operations.search(searchQuery, StockPrice.class, index);
|
||||
@@ -186,19 +186,19 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
|
||||
@Test // DATAES-76
|
||||
public void shouldAddSampleInheritedEntityDocumentToIndex() {
|
||||
|
||||
// given
|
||||
IndexCoordinates index = IndexCoordinates.of("test-index-sample-inherited-mapping-builder").withTypes("mapping");
|
||||
IndexOperations indexOps = operations.indexOps(index);
|
||||
|
||||
// when
|
||||
indexOperations.createIndex(SampleInheritedEntity.class);
|
||||
indexOperations.putMapping(SampleInheritedEntity.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(SampleInheritedEntity.class));
|
||||
Date createdDate = new Date();
|
||||
String message = "msg";
|
||||
String id = "abc";
|
||||
IndexCoordinates index = IndexCoordinates.of("test-index-sample-inherited-mapping-builder").withTypes("mapping");
|
||||
operations.index(new SampleInheritedEntityBuilder(id).createdDate(createdDate).message(message).buildIndex(),
|
||||
index);
|
||||
operations.refresh(SampleInheritedEntity.class);
|
||||
operations.indexOps(SampleInheritedEntity.class).refresh();
|
||||
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
SearchHits<SampleInheritedEntity> result = operations.search(searchQuery, SampleInheritedEntity.class, index);
|
||||
@@ -231,10 +231,13 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
public void shouldHandleReverseRelationship() {
|
||||
|
||||
// given
|
||||
indexOperations.createIndex(User.class);
|
||||
indexOperations.putMapping(User.class);
|
||||
indexOperations.createIndex(Group.class);
|
||||
indexOperations.putMapping(Group.class);
|
||||
IndexOperations indexOpsUser = operations.indexOps(User.class);
|
||||
indexOpsUser.create();
|
||||
indexOpsUser.putMapping(indexOpsUser.createMapping(User.class));
|
||||
|
||||
IndexOperations indexOpsGroup = operations.indexOps(Group.class);
|
||||
indexOpsGroup.create();
|
||||
indexOpsGroup.putMapping(indexOpsGroup.createMapping(Group.class));
|
||||
|
||||
// when
|
||||
|
||||
@@ -245,8 +248,9 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
public void shouldMapBooks() {
|
||||
|
||||
// given
|
||||
indexOperations.createIndex(Book.class);
|
||||
indexOperations.putMapping(Book.class);
|
||||
IndexOperations indexOps = operations.indexOps(Book.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(Book.class));
|
||||
|
||||
// when
|
||||
|
||||
@@ -257,11 +261,12 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
public void shouldUseBothAnalyzer() {
|
||||
|
||||
// given
|
||||
indexOperations.createIndex(Book.class);
|
||||
indexOperations.putMapping(Book.class);
|
||||
IndexOperations indexOps = this.operations.indexOps(Book.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(Book.class));
|
||||
|
||||
// when
|
||||
Map mapping = operations.getMapping(Book.class);
|
||||
Map mapping = indexOps.getMapping();
|
||||
Map descriptionMapping = (Map) ((Map) mapping.get("properties")).get("description");
|
||||
Map prefixDescription = (Map) ((Map) descriptionMapping.get("fields")).get("prefix");
|
||||
|
||||
@@ -298,11 +303,12 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
public void shouldUseCopyTo() {
|
||||
|
||||
// given
|
||||
indexOperations.createIndex(CopyToEntity.class);
|
||||
indexOperations.putMapping(CopyToEntity.class);
|
||||
IndexOperations indexOps = operations.indexOps(CopyToEntity.class);
|
||||
indexOps.create();
|
||||
indexOps.putMapping(indexOps.createMapping(CopyToEntity.class));
|
||||
|
||||
// when
|
||||
Map mapping = operations.getMapping(CopyToEntity.class);
|
||||
Map mapping = indexOps.getMapping();
|
||||
Map properties = (Map) mapping.get("properties");
|
||||
Map fieldFirstName = (Map) properties.get("firstName");
|
||||
Map fieldLastName = (Map) properties.get("lastName");
|
||||
|
||||
@@ -67,19 +67,20 @@ public class CriteriaQueryTests {
|
||||
private final IndexCoordinates index = IndexCoordinates.of("test-index-sample-core-query").withTypes("test-type");
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
indexOperations.deleteIndex(SampleEntity.class);
|
||||
indexOperations.createIndex(SampleEntity.class);
|
||||
indexOperations.putMapping(SampleEntity.class);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations = operations.indexOps(SampleEntity.class);
|
||||
indexOperations.delete();
|
||||
indexOperations.create();
|
||||
indexOperations.putMapping(indexOperations.createMapping(SampleEntity.class));
|
||||
indexOperations.refresh();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(SampleEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,7 +97,7 @@ public class CriteriaQueryTests {
|
||||
indexQuery.setId(documentId);
|
||||
indexQuery.setObject(sampleEntity);
|
||||
operations.index(indexQuery, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
||||
new Criteria("message").contains("test").and("message").contains("some"));
|
||||
|
||||
@@ -139,7 +140,7 @@ public class CriteriaQueryTests {
|
||||
|
||||
indexQueries.add(indexQuery2);
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
||||
new Criteria("message").contains("some").or("message").contains("test"));
|
||||
|
||||
@@ -170,7 +171,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria().and(new Criteria("message").contains("some")));
|
||||
|
||||
// when
|
||||
@@ -201,7 +202,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria().or(new Criteria("message").contains("some")));
|
||||
|
||||
// when
|
||||
@@ -230,7 +231,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("some message"));
|
||||
|
||||
// when
|
||||
@@ -272,7 +273,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("some message"));
|
||||
|
||||
// when
|
||||
@@ -314,7 +315,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
Criteria criteria = new Criteria("message").endsWith("end");
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(criteria);
|
||||
|
||||
@@ -356,7 +357,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
Criteria criteria = new Criteria("message").startsWith("start");
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(criteria);
|
||||
|
||||
@@ -398,7 +399,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("contains"));
|
||||
|
||||
// when
|
||||
@@ -439,7 +440,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").expression("+elasticsearch || test"));
|
||||
|
||||
// when
|
||||
@@ -480,7 +481,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
||||
new Criteria("message").startsWith("some").endsWith("search").contains("message").is("some message search"));
|
||||
|
||||
@@ -522,7 +523,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("foo").not());
|
||||
|
||||
// when
|
||||
@@ -566,7 +567,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(100, 150));
|
||||
|
||||
// when
|
||||
@@ -608,7 +609,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(350, null));
|
||||
|
||||
// when
|
||||
@@ -651,7 +652,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(null, 550));
|
||||
|
||||
// when
|
||||
@@ -694,7 +695,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").lessThanEqual(750));
|
||||
|
||||
// when
|
||||
@@ -737,7 +738,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").greaterThanEqual(950));
|
||||
|
||||
// when
|
||||
@@ -780,7 +781,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("foo").boost(1));
|
||||
|
||||
// when
|
||||
@@ -801,7 +802,7 @@ public class CriteriaQueryTests {
|
||||
indexQueries.add(buildIndex(SampleEntity.builder().id("3").message("ac").build()));
|
||||
|
||||
operations.bulkIndex(indexQueries, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
|
||||
// when
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
||||
@@ -828,7 +829,7 @@ public class CriteriaQueryTests {
|
||||
indexQuery.setId(documentId);
|
||||
indexQuery.setObject(sampleEntity);
|
||||
operations.index(indexQuery, index);
|
||||
indexOperations.refresh(SampleEntity.class);
|
||||
indexOperations.refresh();
|
||||
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("Hello World!"));
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
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.ElasticsearchTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||
@@ -57,10 +58,10 @@ public class ImmutableElasticsearchRepositoryTests {
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
|
||||
operations.deleteIndex(ImmutableEntity.class);
|
||||
operations.createIndex(ImmutableEntity.class);
|
||||
operations.refresh(ImmutableEntity.class);
|
||||
IndexOperations indexOperations = operations.indexOps(ImmutableEntity.class);
|
||||
indexOperations.delete();
|
||||
indexOperations.create();
|
||||
indexOperations.refresh();
|
||||
}
|
||||
|
||||
@Test // DATAES-281
|
||||
|
||||
@@ -19,9 +19,7 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -43,9 +41,4 @@ public class ElasticsearchTemplateConfiguration extends ElasticsearchConfigurati
|
||||
ElasticsearchConverter elasticsearchConverter) {
|
||||
return new ElasticsearchTemplate(elasticsearchClient, elasticsearchConverter);
|
||||
}
|
||||
|
||||
@Bean
|
||||
IndexOperations indexOperations(ElasticsearchOperations elasticsearchOperations) {
|
||||
return elasticsearchOperations.getIndexOperations();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ 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,16 +53,19 @@ public class ComplexCustomMethodRepositoryTests {
|
||||
|
||||
@Autowired private ComplexElasticsearchRepository complexRepository;
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, SampleEntity.class);
|
||||
indexOperations = operations.indexOps(SampleEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(SampleEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,6 +29,7 @@ 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;
|
||||
@@ -51,16 +52,18 @@ public class ComplexCustomMethodRepositoryManualWiringTests {
|
||||
|
||||
@Autowired private ComplexElasticsearchRepositoryManualWiring complexRepository;
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, SampleEntity.class);
|
||||
indexOperations = operations.indexOps(SampleEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(SampleEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -49,6 +49,7 @@ 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,16 +81,18 @@ public abstract class CustomMethodRepositoryBaseTests {
|
||||
|
||||
@Autowired private SampleStreamingCustomMethodRepository streamingRepository;
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, SampleEntity.class);
|
||||
indexOperations = operations.indexOps(SampleEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(SampleEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,6 +30,7 @@ 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;
|
||||
@@ -56,16 +57,18 @@ public class DoubleIDRepositoryTests {
|
||||
|
||||
@Autowired private DoubleIDRepository repository;
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, DoubleIDEntity.class);
|
||||
indexOperations = operations.indexOps(DoubleIDEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void after() {
|
||||
indexOperations.deleteIndex(DoubleIDEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,7 +26,9 @@ 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.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
@@ -56,15 +58,17 @@ public class DynamicIndexEntityTests {
|
||||
|
||||
@Autowired private DynamicIndexRepository repository;
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@Autowired private IndexNameProvider indexNameProvider;
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
indexOperations = operations.indexOps(IndexCoordinates.of("index1"));
|
||||
deleteIndexes();
|
||||
indexOperations.createIndex("index1");
|
||||
indexOperations.createIndex("index2");
|
||||
operations.indexOps(IndexCoordinates.of("index1")).create();
|
||||
operations.indexOps(IndexCoordinates.of("index2")).create();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -74,8 +78,8 @@ public class DynamicIndexEntityTests {
|
||||
|
||||
private void deleteIndexes() {
|
||||
|
||||
indexOperations.deleteIndex("index1");
|
||||
indexOperations.deleteIndex("index2");
|
||||
indexOperations.delete();
|
||||
operations.indexOps(IndexCoordinates.of("index2")).delete();
|
||||
}
|
||||
|
||||
@Test // DATAES-456
|
||||
|
||||
@@ -35,6 +35,7 @@ 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;
|
||||
@@ -62,18 +63,20 @@ public class SpringDataGeoRepositoryTests {
|
||||
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||
static class Config {}
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@Autowired SpringDataGeoRepository repository;
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
IndexInitializer.init(indexOperations, GeoEntity.class);
|
||||
indexOperations = operations.indexOps(GeoEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(GeoEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,6 +30,7 @@ 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;
|
||||
@@ -56,16 +57,19 @@ public class IntegerIDRepositoryTests {
|
||||
|
||||
@Autowired private IntegerIDRepository repository;
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, IntegerIDEntity.class);
|
||||
indexOperations = operations.indexOps(IntegerIDEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(IntegerIDEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -41,6 +41,7 @@ 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;
|
||||
@@ -65,16 +66,19 @@ public class InnerObjectTests {
|
||||
|
||||
@Autowired private SampleElasticSearchBookRepository bookRepository;
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, Book.class);
|
||||
indexOperations = operations.indexOps(Book.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(Book.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.elasticsearch.repositories.setting.dynamic;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.elasticsearch.core.document.Document.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -61,18 +62,19 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
static class Config {}
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@Autowired private DynamicSettingAndMappingEntityRepository repository;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, DynamicSettingAndMappingEntity.class);
|
||||
indexOperations = operations.indexOps(DynamicSettingAndMappingEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(DynamicSettingAndMappingEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test // DATAES-64
|
||||
@@ -82,8 +84,8 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
// delete , create and apply mapping in before method
|
||||
|
||||
// then
|
||||
assertThat(indexOperations.indexExists(DynamicSettingAndMappingEntity.class)).isTrue();
|
||||
Map<String, Object> map = indexOperations.getSettings(DynamicSettingAndMappingEntity.class);
|
||||
assertThat(indexOperations.exists()).isTrue();
|
||||
Map<String, Object> map = indexOperations.getSettings();
|
||||
assertThat(map.containsKey("index.number_of_replicas")).isTrue();
|
||||
assertThat(map.containsKey("index.number_of_shards")).isTrue();
|
||||
assertThat(map.containsKey("index.analysis.analyzer.emailAnalyzer.tokenizer")).isTrue();
|
||||
@@ -134,7 +136,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
// delete , create and apply mapping in before method
|
||||
|
||||
// when
|
||||
Map<String, Object> mapping = indexOperations.getMapping(DynamicSettingAndMappingEntity.class);
|
||||
Map<String, Object> mapping = indexOperations.getMapping();
|
||||
|
||||
// then
|
||||
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
||||
@@ -149,9 +151,9 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
public void shouldCreateMappingWithSpecifiedMappings() {
|
||||
|
||||
// given
|
||||
indexOperations.deleteIndex(DynamicSettingAndMappingEntity.class);
|
||||
indexOperations.createIndex(DynamicSettingAndMappingEntity.class);
|
||||
indexOperations.refresh(DynamicSettingAndMappingEntity.class);
|
||||
indexOperations.delete();
|
||||
indexOperations.create();
|
||||
indexOperations.refresh();
|
||||
|
||||
// when
|
||||
String mappings = "{\n" + //
|
||||
@@ -159,11 +161,11 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
" \"email\" : {\"type\" : \"text\", \"analyzer\" : \"emailAnalyzer\" }\n" + //
|
||||
" }\n" + //
|
||||
'}';
|
||||
indexOperations.putMapping(DynamicSettingAndMappingEntity.class, mappings);
|
||||
indexOperations.refresh(DynamicSettingAndMappingEntity.class);
|
||||
indexOperations.putMapping(parse(mappings));
|
||||
indexOperations.refresh();
|
||||
|
||||
// then
|
||||
Map<String, Object> mapping = indexOperations.getMapping(DynamicSettingAndMappingEntity.class);
|
||||
Map<String, Object> mapping = indexOperations.getMapping();
|
||||
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
||||
assertThat(mapping).isNotNull();
|
||||
assertThat(properties).isNotNull();
|
||||
@@ -178,7 +180,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
// given
|
||||
|
||||
// then
|
||||
Map<String, Object> mapping = indexOperations.getMapping(DynamicSettingAndMappingEntity.class);
|
||||
Map<String, Object> mapping = indexOperations.getMapping();
|
||||
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
||||
assertThat(mapping).isNotNull();
|
||||
assertThat(properties).isNotNull();
|
||||
|
||||
@@ -53,16 +53,17 @@ public class FieldDynamicMappingEntityRepositoryTests {
|
||||
static class Config {}
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, FieldDynamicMappingEntity.class);
|
||||
indexOperations = operations.indexOps(FieldDynamicMappingEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(FieldDynamicMappingEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test // DATAES-209
|
||||
|
||||
@@ -55,16 +55,17 @@ public class SpELEntityTests {
|
||||
@Autowired private SpELRepository repository;
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, SpELEntity.class);
|
||||
indexOperations = operations.indexOps(SpELEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex("test-index-abz-*");
|
||||
operations.indexOps(IndexCoordinates.of("test-index-abz-*")).delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -60,16 +60,17 @@ public class SynonymRepositoryTests {
|
||||
@Autowired private SynonymRepository repository;
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, SynonymEntity.class);
|
||||
indexOperations = operations.indexOps(SynonymEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(SynonymEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -45,6 +45,7 @@ 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;
|
||||
@@ -76,16 +77,18 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
|
||||
@Autowired private SampleUUIDKeyedElasticsearchRepository repository;
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, SampleEntityUUIDKeyed.class);
|
||||
indexOperations = operations.indexOps(SampleEntityUUIDKeyed.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(SampleEntityUUIDKeyed.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -37,6 +37,7 @@ 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;
|
||||
@@ -65,11 +66,13 @@ class QueryKeywordsTests {
|
||||
|
||||
@Autowired private ProductRepository repository;
|
||||
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
@Autowired ElasticsearchOperations operations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, Product.class);
|
||||
indexOperations = operations.indexOps(Product.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
|
||||
Product product1 = Product.builder().id("1").name("Sugar").text("Cane sugar").price(1.0f).available(false)
|
||||
.sortName("sort5").build();
|
||||
@@ -89,7 +92,7 @@ class QueryKeywordsTests {
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(Product.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -81,16 +81,17 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
@Autowired private SampleElasticsearchRepository repository;
|
||||
|
||||
@Autowired private ElasticsearchOperations operations;
|
||||
@Autowired private IndexOperations indexOperations;
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(indexOperations, SampleEntity.class);
|
||||
indexOperations = operations.indexOps(SampleEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
indexOperations.deleteIndex(SampleEntity.class);
|
||||
indexOperations.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,27 +32,22 @@ public class IndexInitializer {
|
||||
*
|
||||
* @param operations
|
||||
* @param clazz
|
||||
* @deprecated since 4.0, use {@link IndexInitializer#init(IndexOperations, Class)}
|
||||
* @deprecated since 4.0, use {@link IndexInitializer#init(IndexOperations)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void init(ElasticsearchOperations operations, Class<?> clazz) {
|
||||
IndexOperations indexOperations = operations.getIndexOperations();
|
||||
indexOperations.deleteIndex(clazz);
|
||||
indexOperations.createIndex(clazz);
|
||||
indexOperations.putMapping(clazz);
|
||||
indexOperations.refresh(clazz);
|
||||
init(operations.indexOps(clazz));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a fresh index with mappings for {@link Class}. Drops the index if it exists before creation.
|
||||
*
|
||||
* @param operations
|
||||
* @param clazz
|
||||
* @param indexOperations
|
||||
*/
|
||||
public static void init(IndexOperations operations, Class<?> clazz) {
|
||||
operations.deleteIndex(clazz);
|
||||
operations.createIndex(clazz);
|
||||
operations.putMapping(clazz);
|
||||
operations.refresh(clazz);
|
||||
public static void init(IndexOperations indexOperations) {
|
||||
indexOperations.delete();
|
||||
indexOperations.create();
|
||||
indexOperations.putMapping(indexOperations.createMapping());
|
||||
indexOperations.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user