Search in sources :

Example 1 with IndexOperations

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

the class ImmutableElasticsearchRepositoryTests method tearDown.

@AfterEach
void tearDown() {
    IndexOperations indexOperations = operations.indexOps(ImmutableEntity.class);
    indexOperations.delete();
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) AfterEach(org.junit.jupiter.api.AfterEach)

Example 2 with IndexOperations

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

the class FieldNamingStrategyIntegrationTests method setUp.

@BeforeEach
void setUp() {
    IndexOperations indexOps = this.operations.indexOps(Entity.class);
    indexOps.delete();
    indexOps.create();
    indexOps.putMapping();
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with IndexOperations

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

the class IndexOperationIntegrationTests method shouldReturnInformationList.

// #1646, #1718
@Test
@DisplayName("should return a list of info for specific index")
void shouldReturnInformationList() throws JSONException {
    IndexOperations indexOps = operations.indexOps(EntityWithSettingsAndMappings.class);
    String aliasName = "testindexinformationindex";
    indexOps.createWithMapping();
    AliasActionParameters parameters = AliasActionParameters.builder().withAliases(aliasName).withIndices(INDEX_NAME).withIsHidden(false).withIsWriteIndex(false).withRouting("indexrouting").withSearchRouting("searchrouting").build();
    indexOps.alias(new AliasActions(new AliasAction.Add(parameters)));
    List<IndexInformation> indexInformationList = indexOps.getInformation();
    IndexInformation indexInformation = indexInformationList.get(0);
    assertThat(indexInformationList.size()).isEqualTo(1);
    assertThat(indexInformation.getName()).isEqualTo(INDEX_NAME);
    assertThat(indexInformation.getSettings().get("index.number_of_shards")).isEqualTo("1");
    assertThat(indexInformation.getSettings().get("index.number_of_replicas")).isEqualTo("0");
    assertThat(indexInformation.getSettings().get("index.analysis.analyzer.emailAnalyzer.type")).isEqualTo("custom");
    assertThat(indexInformation.getAliases()).hasSize(1);
    AliasData aliasData = indexInformation.getAliases().get(0);
    assertThat(aliasData.getAlias()).isEqualTo(aliasName);
    assertThat(aliasData.isHidden()).isEqualTo(false);
    assertThat(aliasData.isWriteIndex()).isEqualTo(false);
    assertThat(aliasData.getIndexRouting()).isEqualTo("indexrouting");
    assertThat(aliasData.getSearchRouting()).isEqualTo("searchrouting");
    String expectedMappings = // 
    "{\n" + // 
    "  \"properties\": {\n" + // 
    "    \"email\": {\n" + // 
    "      \"type\": \"text\",\n" + // 
    "      \"analyzer\": \"emailAnalyzer\"\n" + // 
    "    }\n" + // 
    "  }\n" + // 
    "}";
    JSONAssert.assertEquals(expectedMappings, indexInformation.getMapping().toJson(), false);
}
Also used : IndexInformation(org.springframework.data.elasticsearch.core.IndexInformation) 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 4 with IndexOperations

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

the class IndexTemplateIntegrationTests method shouldCreateTemplate.

// DATAES-612
@Test
void shouldCreateTemplate() {
    IndexOperations indexOps = operations.indexOps(IndexCoordinates.of("dont-care"));
    org.springframework.data.elasticsearch.core.document.Document mapping = indexOps.createMapping(TemplateClass.class);
    Settings settings = indexOps.createSettings(TemplateClass.class);
    AliasActions aliasActions = new AliasActions(new AliasAction.Add(AliasActionParameters.builderForTemplate().withAliases("alias1", "alias2").build()));
    PutTemplateRequest putTemplateRequest = // 
    PutTemplateRequest.builder("test-template", "log-*").withSettings(// 
    settings).withMappings(// 
    mapping).withAliasActions(// 
    aliasActions).build();
    boolean acknowledged = indexOps.putTemplate(putTemplateRequest);
    assertThat(acknowledged).isTrue();
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 5 with IndexOperations

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

the class IndexTemplateIntegrationTests method shouldCheckExists.

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

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