Search in sources :

Example 6 with PutIndexTemplateRequest

use of org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest in project crate by crate.

the class AlterTableOperation method updateTemplate.

private CompletableFuture<Long> updateTemplate(Map<String, Object> newMappings, Settings newSettings, TableIdent tableIdent) {
    String templateName = PartitionName.templateName(tableIdent.schema(), tableIdent.name());
    IndexTemplateMetaData indexTemplateMetaData = clusterService.state().metaData().templates().get(templateName);
    if (indexTemplateMetaData == null) {
        return CompletableFutures.failedFuture(new RuntimeException("Template for partitioned table is missing"));
    }
    // merge mappings
    Map<String, Object> mapping = mergeTemplateMapping(indexTemplateMetaData, newMappings);
    // merge settings
    Settings.Builder settingsBuilder = Settings.builder();
    settingsBuilder.put(indexTemplateMetaData.settings());
    settingsBuilder.put(newSettings);
    PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName).create(false).mapping(Constants.DEFAULT_MAPPING_TYPE, mapping).order(indexTemplateMetaData.order()).settings(settingsBuilder.build()).template(indexTemplateMetaData.template());
    for (ObjectObjectCursor<String, AliasMetaData> container : indexTemplateMetaData.aliases()) {
        Alias alias = new Alias(container.key);
        request.alias(alias);
    }
    FutureActionListener<PutIndexTemplateResponse, Long> listener = new FutureActionListener<>(LONG_NULL_FUNCTION);
    transportActionProvider.transportPutIndexTemplateAction().execute(request, listener);
    return listener;
}
Also used : PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) FutureActionListener(io.crate.action.FutureActionListener) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) Alias(org.elasticsearch.action.admin.indices.alias.Alias) PutIndexTemplateResponse(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse) Settings(org.elasticsearch.common.settings.Settings)

Example 7 with PutIndexTemplateRequest

use of org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest in project graylog2-server by Graylog2.

the class Indices method ensureIndexTemplate.

private void ensureIndexTemplate(IndexSet indexSet) {
    final Map<String, Object> template = indexMapping.messageTemplate(indexSet.getIndexWildcard(), indexSet.getConfig().indexAnalyzer());
    final PutIndexTemplateRequest itr = c.admin().indices().preparePutTemplate(indexSet.getConfig().indexTemplateName()).setOrder(// Make sure templates with "order: 0" and higher are applied after our template!
    -1).setSource(template).request();
    try {
        final boolean acknowledged = c.admin().indices().putTemplate(itr).actionGet().isAcknowledged();
        if (acknowledged) {
            LOG.info("Created Graylog index template \"{}\" in Elasticsearch.", indexSet.getConfig().indexTemplateName());
        }
    } catch (Exception e) {
        LOG.error("Unable to create the Graylog index template: " + indexSet.getConfig().indexTemplateName(), e);
    }
}
Also used : PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexClosedException(org.elasticsearch.indices.IndexClosedException) IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) IOException(java.io.IOException)

Example 8 with PutIndexTemplateRequest

use of org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest in project zipkin by openzipkin.

the class NativeClient method ensureTemplate.

@Override
public void ensureTemplate(String name, String indexTemplate) {
    GetIndexTemplatesResponse existingTemplates = client.admin().indices().getTemplates(new GetIndexTemplatesRequest(name)).actionGet();
    if (!existingTemplates.getIndexTemplates().isEmpty()) {
        return;
    }
    client.admin().indices().putTemplate(new PutIndexTemplateRequest(name).source(indexTemplate)).actionGet();
}
Also used : GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest)

Example 9 with PutIndexTemplateRequest

use of org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest in project zipkin by openzipkin.

the class LazyClientTest method defaultsToUnanalyzedTraceId_2x.

@Test
public void defaultsToUnanalyzedTraceId_2x() {
    LazyClient lazyClient = new LazyClient(ElasticsearchStorage.builder());
    PutIndexTemplateRequest request = new PutIndexTemplateRequest("zipkin").source(lazyClient.versionSpecificTemplate("2.4.0"));
    assertThat(request.mappings().get("span")).contains("\"traceId\":{\"type\":\"string\",\"index\":\"not_analyzed\"}");
}
Also used : PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) Test(org.junit.Test)

Aggregations

PutIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest)9 Test (org.junit.Test)4 IOException (java.io.IOException)2 Alias (org.elasticsearch.action.admin.indices.alias.Alias)2 Settings (org.elasticsearch.common.settings.Settings)2 FutureActionListener (io.crate.action.FutureActionListener)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 GetIndexTemplatesRequest (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest)1 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)1 PutIndexTemplateResponse (org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 AliasMetaData (org.elasticsearch.cluster.metadata.AliasMetaData)1 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)1 Strings (org.elasticsearch.common.Strings)1 DeprecationLogger (org.elasticsearch.common.logging.DeprecationLogger)1 Loggers (org.elasticsearch.common.logging.Loggers)1 IndexClosedException (org.elasticsearch.indices.IndexClosedException)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1