Search in sources :

Example 6 with IndexOperations

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

the class IndexTemplateIntegrationTests method shouldDeleteTemplate.

// DATAES-612
@Test
void shouldDeleteTemplate() {
    IndexOperations indexOps = operations.indexOps(IndexCoordinates.of("dont-care"));
    String templateName = "template" + UUID.randomUUID().toString();
    ExistsTemplateRequest existsTemplateRequest = new ExistsTemplateRequest(templateName);
    PutTemplateRequest putTemplateRequest = // 
    PutTemplateRequest.builder(templateName, "log-*").withOrder(// 
    11).withVersion(// 
    42).build();
    boolean acknowledged = indexOps.putTemplate(putTemplateRequest);
    assertThat(acknowledged).isTrue();
    boolean exists = indexOps.existsTemplate(existsTemplateRequest);
    assertThat(exists).isTrue();
    acknowledged = indexOps.deleteTemplate(new DeleteTemplateRequest(templateName));
    assertThat(acknowledged).isTrue();
    exists = indexOps.existsTemplate(existsTemplateRequest);
    assertThat(exists).isFalse();
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 7 with IndexOperations

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

the class MappingBuilderIntegrationTests method shouldWriteCorrectTermVectorValues.

// DATAES-991
@Test
@DisplayName("should write correct TermVector values")
void shouldWriteCorrectTermVectorValues() {
    IndexOperations indexOps = operations.indexOps(TermVectorFieldEntity.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 8 with IndexOperations

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

the class MappingBuilderIntegrationTests method shouldUseKeywordNormalizer.

// DATAES-492
@Test
@SuppressWarnings("rawtypes")
public void shouldUseKeywordNormalizer() {
    // given
    IndexOperations indexOps = operations.indexOps(NormalizerEntity.class);
    indexOps.create();
    indexOps.putMapping();
    // when
    Map mapping = indexOps.getMapping();
    Map properties = (Map) mapping.get("properties");
    Map fieldName = (Map) properties.get("name");
    Map fieldDescriptionLowerCase = (Map) ((Map) ((Map) properties.get("description")).get("fields")).get("lower_case");
    // then
    assertThat(fieldName.get("type")).isEqualTo("keyword");
    assertThat(fieldName.get("normalizer")).isEqualTo("lower_case_normalizer");
    assertThat(fieldDescriptionLowerCase.get("type")).isEqualTo("keyword");
    assertThat(fieldDescriptionLowerCase.get("normalizer")).isEqualTo("lower_case_normalizer");
}
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 9 with IndexOperations

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

the class MappingBuilderIntegrationTests method shouldUseCopyTo.

// DATAES-503
@Test
@SuppressWarnings("rawtypes")
public void shouldUseCopyTo() {
    // given
    IndexOperations indexOps = operations.indexOps(CopyToEntity.class);
    indexOps.create();
    indexOps.putMapping(CopyToEntity.class);
    // when
    Map mapping = indexOps.getMapping();
    Map properties = (Map) mapping.get("properties");
    Map fieldFirstName = (Map) properties.get("firstName");
    Map fieldLastName = (Map) properties.get("lastName");
    // then
    List<String> copyToValue = Collections.singletonList("name");
    assertThat(fieldFirstName.get("copy_to")).isEqualTo(copyToValue);
    assertThat(fieldLastName.get("copy_to")).isEqualTo(copyToValue);
}
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 10 with IndexOperations

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

the class MappingBuilderIntegrationTests method shouldWriteRuntimeFields.

// #1816
@Test
@DisplayName("should write runtime fields")
void shouldWriteRuntimeFields() {
    IndexOperations indexOps = operations.indexOps(RuntimeFieldEntity.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