Search in sources :

Example 31 with IndexOperations

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

the class MappingBuilderIntegrationTests method shouldWriteDenseVectorFieldMapping.

// #1700
@Test
@DisplayName("should write dense_vector field mapping")
void shouldWriteDenseVectorFieldMapping() {
    IndexOperations indexOps = operations.indexOps(DenseVectorEntity.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 32 with IndexOperations

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

the class IndexTemplateIntegrationTests method shouldReturnNullOnNonExistingGetTemplate.

// DATAES-612
@Test
void shouldReturnNullOnNonExistingGetTemplate() {
    String templateName = "template" + UUID.randomUUID().toString();
    IndexOperations indexOps = operations.indexOps(IndexCoordinates.of("dont-care"));
    GetTemplateRequest getTemplateRequest = new GetTemplateRequest(templateName);
    TemplateData templateData = indexOps.getTemplate(getTemplateRequest);
    assertThat(templateData).isNull();
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 33 with IndexOperations

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

the class IndexTemplateIntegrationTests method shouldGetTemplate.

// DATAES-612
@Test
void shouldGetTemplate() throws JSONException {
    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).withOrder(// 
    11).withVersion(// 
    42).build();
    boolean acknowledged = indexOps.putTemplate(putTemplateRequest);
    assertThat(acknowledged).isTrue();
    GetTemplateRequest getTemplateRequest = new GetTemplateRequest(putTemplateRequest.getName());
    TemplateData templateData = indexOps.getTemplate(getTemplateRequest);
    assertThat(templateData).isNotNull();
    assertThat(templateData.getIndexPatterns()).containsExactlyInAnyOrder(putTemplateRequest.getIndexPatterns());
    assertEquals(settings.toJson(), templateData.getSettings().toJson(), false);
    assertEquals(mapping.toJson(), templateData.getMapping().toJson(), false);
    Map<String, AliasData> aliases = templateData.getAliases();
    assertThat(aliases).hasSize(2);
    AliasData alias1 = aliases.get("alias1");
    assertThat(alias1.getAlias()).isEqualTo("alias1");
    AliasData alias2 = aliases.get("alias2");
    assertThat(alias2.getAlias()).isEqualTo("alias2");
    assertThat(templateData.getOrder()).isEqualTo(putTemplateRequest.getOrder());
    assertThat(templateData.getVersion()).isEqualTo(putTemplateRequest.getVersion());
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 34 with IndexOperations

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

the class GeoJsonIntegrationTests method setUp.

// endregion
// region setup
@BeforeEach
void setUp() {
    indexOps = operations.indexOps(GeoJsonEntity.class);
    indexOps.delete();
    indexOps.create();
    indexOps.putMapping();
    IndexOperations indexOpsArea = operations.indexOps(Area.class);
    indexOpsArea.delete();
    indexOpsArea.create();
    indexOpsArea.putMapping();
    operations.save(Arrays.asList(area10To20, area30To40));
    indexOpsArea.refresh();
}
Also used : IndexOperations(org.springframework.data.elasticsearch.core.IndexOperations) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 35 with IndexOperations

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

the class EntityCustomConversionIntegrationTests method setUp.

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

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