Search in sources :

Example 1 with IndexInformation

use of org.springframework.data.elasticsearch.core.IndexInformation 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)

Aggregations

DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1 IndexInformation (org.springframework.data.elasticsearch.core.IndexInformation)1 IndexOperations (org.springframework.data.elasticsearch.core.IndexOperations)1 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)1