WARNING: Deprecated in 7.15.0.
The Java REST Client is deprecated in favor of the Java API Client.
Create or update component template API
editCreate or update component template API
editCreates or updates a component template.
Request
editA PutComponentTemplateRequest
specifies the name of the component template and the template definition,
which can consist of the settings, mappings or aliases, together with a version (which
can be used to simply component template management by external systems) and a metadata
map consisting of user specific information.
PutComponentTemplateRequest request = new PutComponentTemplateRequest() .name("ct1"); Settings settings = Settings.builder() .put("index.number_of_shards", 3) .put("index.number_of_replicas", 1) .build(); String mappingJson = "{\n" + " \"properties\": {\n" + " \"message\": {\n" + " \"type\": \"text\"\n" + " }\n" + " }\n" + "}"; AliasMetadata twitterAlias = AliasMetadata.builder("twitter_alias").build(); Map<String, AliasMetadata> aliases = new HashMap<>(); aliases.put("twitter_alias", twitterAlias); Template template = new Template(settings, new CompressedXContent(mappingJson), aliases); request.componentTemplate(new ComponentTemplate(template, null, null)); assertTrue(client.cluster().putComponentTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
The name of the component template |
|
Template configuration containing the settings, mappings and aliases for this component template |
Version
editA component template can optionally specify a version number which can be used to simplify template management by external systems.
PutComponentTemplateRequest request = new PutComponentTemplateRequest() .name("ct1"); Settings settings = Settings.builder() .put("index.number_of_replicas", 3) .build(); Template template = new Template(settings, null, null); request.componentTemplate(new ComponentTemplate(template, 3L, null)); assertTrue(client.cluster().putComponentTemplate(request, RequestOptions.DEFAULT).isAcknowledged());