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;
}
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);
}
}
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();
}
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\"}");
}
Aggregations