IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Put Component Template API
editPut Component Template API
editThe Put Component Template API allows to create or change a component template.
Put 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());