Search in sources :

Example 11 with IndexOperations

use of org.springframework.data.elasticsearch.core.IndexOperations in project spring-data-elasticsearch by spring-projects.

the class MappingBuilderIntegrationTests method shouldHandleReverseRelationship.

// DATAES-260 - StackOverflow when two reverse relationship.
@Test
public void shouldHandleReverseRelationship() {
    // given
    IndexOperations indexOpsUser = operations.indexOps(User.class);
    indexOpsUser.create();
    indexOpsUser.putMapping(User.class);
    indexNameProvider.increment();
    IndexOperations indexOpsGroup = operations.indexOps(Group.class);
    indexOpsGroup.create();
    indexOpsGroup.putMapping(Group.class);
// when
// then
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 12 with IndexOperations

use of org.springframework.data.elasticsearch.core.IndexOperations in project spring-data-elasticsearch by spring-projects.

the class MappingBuilderIntegrationTests method shouldAddSampleInheritedEntityDocumentToIndex.

// DATAES-76
@Test
public void shouldAddSampleInheritedEntityDocumentToIndex() {
    // given
    IndexOperations indexOps = operations.indexOps(SampleInheritedEntity.class);
    // when
    indexOps.create();
    indexOps.putMapping(SampleInheritedEntity.class);
    Date createdDate = new Date();
    String message = "msg";
    String id = "abc";
    operations.index(new SampleInheritedEntityBuilder(id).createdDate(createdDate).message(message).buildIndex(), IndexCoordinates.of(indexNameProvider.indexName()));
    NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
    SearchHits<SampleInheritedEntity> result = operations.search(searchQuery, SampleInheritedEntity.class);
    // then
    assertThat(result).hasSize(1);
    SampleInheritedEntity entry = result.getSearchHit(0).getContent();
    assertThat(entry.getCreatedDate()).isEqualTo(createdDate);
    assertThat(entry.getMessage()).isEqualTo(message);
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) Date(java.util.Date) LocalDate(java.time.LocalDate) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 13 with IndexOperations

use of org.springframework.data.elasticsearch.core.IndexOperations in project spring-data-elasticsearch by spring-projects.

the class MappingBuilderIntegrationTests method shouldWriteDynamicMappingAnnotations.

// #1767
@Test
@DisplayName("should write dynamic mapping annotations")
void shouldWriteDynamicMappingAnnotations() {
    IndexOperations indexOps = operations.indexOps(DynamicMappingAnnotationEntity.class);
    indexOps.create();
    indexOps.putMapping();
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 14 with IndexOperations

use of org.springframework.data.elasticsearch.core.IndexOperations in project spring-data-elasticsearch by spring-projects.

the class MappingBuilderIntegrationTests method shouldUseBothAnalyzer.

// DATAES-420
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldUseBothAnalyzer() {
    // given
    IndexOperations indexOps = this.operations.indexOps(Book.class);
    indexOps.create();
    indexOps.putMapping(Book.class);
    // when
    Map mapping = indexOps.getMapping();
    Map descriptionMapping = (Map) ((Map) mapping.get("properties")).get("description");
    Map prefixDescription = (Map) ((Map) descriptionMapping.get("fields")).get("prefix");
    // then
    assertThat(prefixDescription).hasSize(3);
    assertThat(prefixDescription.get("type")).isEqualTo("text");
    assertThat(prefixDescription.get("analyzer")).isEqualTo("stop");
    assertThat(prefixDescription.get("search_analyzer")).isEqualTo("standard");
    assertThat(descriptionMapping.get("type")).isEqualTo("text");
    assertThat(descriptionMapping.get("analyzer")).isEqualTo("whitespace");
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 15 with IndexOperations

use of org.springframework.data.elasticsearch.core.IndexOperations in project spring-data-elasticsearch by spring-projects.

the class MappingBuilderIntegrationTests method shouldWriteMappingForDisabledEntity.

// #1370
@Test
@DisplayName("should write mapping for disabled entity")
void shouldWriteMappingForDisabledEntity() {
    IndexOperations indexOps = operations.indexOps(DisabledMappingEntity.class);
    indexOps.create();
    indexOps.putMapping();
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

IndexOperations (org.springframework.data.elasticsearch.core.IndexOperations)35 Test (org.junit.jupiter.api.Test)24 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)24 DisplayName (org.junit.jupiter.api.DisplayName)11 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Map (java.util.Map)5 HashMap (java.util.HashMap)3 AfterEach (org.junit.jupiter.api.AfterEach)3 EsProduct (com.macro.mall.search.domain.EsProduct)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 NativeSearchQuery (org.springframework.data.elasticsearch.core.query.NativeSearchQuery)2 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)2 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 IndexInformation (org.springframework.data.elasticsearch.core.IndexInformation)1 IndexCoordinates (org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)1