Create or update component template API

edit

Create or update component template API

edit

Creates or updates a component template.

Request

edit

A 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

edit

A 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());

The version number of the template