Search in sources :

Example 1 with Settings

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

the class ResponseConverter method getTemplateData.

// endregion
// region templates
@Nullable
public static TemplateData getTemplateData(GetIndexTemplatesResponse getIndexTemplatesResponse, String templateName) {
    for (IndexTemplateMetadata indexTemplateMetadata : getIndexTemplatesResponse.getIndexTemplates()) {
        if (indexTemplateMetadata.name().equals(templateName)) {
            Settings settings = new Settings();
            org.elasticsearch.common.settings.Settings templateSettings = indexTemplateMetadata.settings();
            templateSettings.keySet().forEach(key -> settings.put(key, templateSettings.get(key)));
            Map<String, AliasData> aliases = new LinkedHashMap<>();
            ImmutableOpenMap<String, AliasMetadata> aliasesResponse = indexTemplateMetadata.aliases();
            Iterator<String> keysIt = aliasesResponse.keysIt();
            while (keysIt.hasNext()) {
                String key = keysIt.next();
                aliases.put(key, ResponseConverter.toAliasData(aliasesResponse.get(key)));
            }
            return // 
            TemplateData.builder().withIndexPatterns(indexTemplateMetadata.patterns().toArray(new String[0])).withSettings(// 
            settings).withMapping(// 
            Document.from(indexTemplateMetadata.mappings().getSourceAsMap())).withAliases(// 
            aliases).withOrder(// 
            indexTemplateMetadata.order()).withVersion(indexTemplateMetadata.version()).build();
        }
    }
    return null;
}
Also used : AliasData(org.springframework.data.elasticsearch.core.index.AliasData) AliasMetadata(org.elasticsearch.cluster.metadata.AliasMetadata) IndexTemplateMetadata(org.elasticsearch.client.indices.IndexTemplateMetadata) Settings(org.springframework.data.elasticsearch.core.index.Settings) LinkedHashMap(java.util.LinkedHashMap) Nullable(org.springframework.lang.Nullable)

Example 2 with Settings

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

the class ResponseConverter method settingsFromGetIndexResponse.

/**
 * extract the index settings information from a given index
 *
 * @param getIndexResponse the elastic GetIndexResponse
 * @param indexName the index name
 * @return a document that represents {@link Settings}
 */
private static Settings settingsFromGetIndexResponse(GetIndexResponse getIndexResponse, String indexName) {
    Settings settings = new Settings();
    org.elasticsearch.common.settings.Settings indexSettings = getIndexResponse.getSettings().get(indexName);
    if (!indexSettings.isEmpty()) {
        for (String key : indexSettings.keySet()) {
            settings.put(key, indexSettings.get(key));
        }
    }
    return settings;
}
Also used : Settings(org.springframework.data.elasticsearch.core.index.Settings)

Example 3 with Settings

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

the class ResponseConverter method getIndexInformations.

/**
 * get the index informations from a {@link org.elasticsearch.action.admin.indices.get.GetIndexResponse} (transport
 * client)
 *
 * @param getIndexResponse the index response, must not be {@literal null}
 * @return list of {@link IndexInformation}s for the different indices
 */
public static List<IndexInformation> getIndexInformations(org.elasticsearch.action.admin.indices.get.GetIndexResponse getIndexResponse) {
    List<IndexInformation> indexInformationList = new ArrayList<>();
    for (String indexName : getIndexResponse.getIndices()) {
        Settings settings = settingsFromGetIndexResponse(getIndexResponse, indexName);
        Document mappings = mappingsFromGetIndexResponse(getIndexResponse, indexName);
        List<AliasData> aliases = aliasDataFromIndexResponse(getIndexResponse, indexName);
        indexInformationList.add(IndexInformation.of(indexName, settings, mappings, aliases));
    }
    return indexInformationList;
}
Also used : AliasData(org.springframework.data.elasticsearch.core.index.AliasData) ArrayList(java.util.ArrayList) Document(org.springframework.data.elasticsearch.core.document.Document) Settings(org.springframework.data.elasticsearch.core.index.Settings)

Example 4 with Settings

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

the class ReactiveIndexOperationsTest method shouldGetTemplate.

// DATAES-612
@Test
void shouldGetTemplate() throws JSONException {
    ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
    org.springframework.data.elasticsearch.core.document.Document mapping = indexOps.createMapping(TemplateClass.class).block();
    Settings settings = indexOps.createSettings(TemplateClass.class).block();
    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).block();
    assertThat(acknowledged).isTrue();
    GetTemplateRequest getTemplateRequest = new GetTemplateRequest(putTemplateRequest.getName());
    TemplateData templateData = indexOps.getTemplate(getTemplateRequest).block();
    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 : PutTemplateRequest(org.springframework.data.elasticsearch.core.index.PutTemplateRequest) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) AliasData(org.springframework.data.elasticsearch.core.index.AliasData) TemplateData(org.springframework.data.elasticsearch.core.index.TemplateData) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) GetTemplateRequest(org.springframework.data.elasticsearch.core.index.GetTemplateRequest) Settings(org.springframework.data.elasticsearch.core.index.Settings) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 5 with Settings

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

the class ResponseConverter method getIndexInformations.

// endregion
// region index informations
/**
 * get the index informations from a {@link GetIndexResponse}
 *
 * @param getIndexResponse the index response, must not be {@literal null}
 * @return list of {@link IndexInformation}s for the different indices
 */
public static List<IndexInformation> getIndexInformations(GetIndexResponse getIndexResponse) {
    Assert.notNull(getIndexResponse, "getIndexResponse must not be null");
    List<IndexInformation> indexInformationList = new ArrayList<>();
    for (String indexName : getIndexResponse.getIndices()) {
        Settings settings = settingsFromGetIndexResponse(getIndexResponse, indexName);
        Document mappings = mappingsFromGetIndexResponse(getIndexResponse, indexName);
        List<AliasData> aliases = aliasDataFromIndexResponse(getIndexResponse, indexName);
        indexInformationList.add(IndexInformation.of(indexName, settings, mappings, aliases));
    }
    return indexInformationList;
}
Also used : AliasData(org.springframework.data.elasticsearch.core.index.AliasData) ArrayList(java.util.ArrayList) Document(org.springframework.data.elasticsearch.core.document.Document) Settings(org.springframework.data.elasticsearch.core.index.Settings)

Aggregations

Settings (org.springframework.data.elasticsearch.core.index.Settings)6 AliasData (org.springframework.data.elasticsearch.core.index.AliasData)4 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 Document (org.springframework.data.elasticsearch.core.document.Document)2 AliasAction (org.springframework.data.elasticsearch.core.index.AliasAction)2 AliasActions (org.springframework.data.elasticsearch.core.index.AliasActions)2 PutTemplateRequest (org.springframework.data.elasticsearch.core.index.PutTemplateRequest)2 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)2 LinkedHashMap (java.util.LinkedHashMap)1 IndexTemplateMetadata (org.elasticsearch.client.indices.IndexTemplateMetadata)1 AliasMetadata (org.elasticsearch.cluster.metadata.AliasMetadata)1 GetTemplateRequest (org.springframework.data.elasticsearch.core.index.GetTemplateRequest)1 TemplateData (org.springframework.data.elasticsearch.core.index.TemplateData)1 Nullable (org.springframework.lang.Nullable)1