# Some questions about PutComponentTemplateRequest in Java API

**URL:** <https://discuss.elastic.co/t/some-questions-about-putcomponenttemplaterequest-in-java-api/308308>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 28, 2022, 2:58am UTC](https://discuss.elastic.co/t/some-questions-about-putcomponenttemplaterequest-in-java-api/308308 "2022-06-28T02:58:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![black\_t](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/black_t/32/107643_2.png) [@black\_t](https://discuss.elastic.co/u/black_t)\
**Post date:** [June 28, 2022, 2:58am UTC](https://discuss.elastic.co/t/some-questions-about-putcomponenttemplaterequest-in-java-api/308308/1 "2022-06-28T02:58:47Z")

</div>

Hi,guys.  
When i use the Elasticsearch of version 7.17.2, i found something when i use the PutComponentTemplateRequest.  
i used 7.11.1 in my last project, so i refer the [guide document](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-cluster-put-component-template.html) and follow it to create :

```auto
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());

```

this way is easy for me, when i need add something else , i can just edit the string and redeploy it.

but when i use the elasticsearch of 7.17.2, i can not found any guide documentation to know how to use it.  
i read the source code and i found this way also can create a PutComponentTemplateRequest :

```auto
PutComponentTemplateRequest request = PutComponentTemplateRequest.of(b -> {

  IndexSettingsAnalysis analysis = IndexSettingsAnalysis.of(analysisBuilder -> {
	  Analyzer analyzer = Analyzer.of(analyzerBuilder -> {
		 return analyzerBuilder.custom(CustomAnalyzer.of(customAnalyzerBuilder -> {
			  return customAnalyzerBuilder.filter("icu_folding", "word_delimiter_graph")
					  .charFilter("icu_normalizer", "html_strip")
					  .tokenizer("icu_tokenizer");
		  }));
	  });
	 return analysisBuilder.analyzer("custom_text_analyzer", analyzer);
  });
  IndexSettings settings = IndexSettings.of(indexBuild -> {
	  return indexBuild.numberOfShards("2").numberOfReplicas("1").maxResultWindow(100000)
			  .analysis(analysis);
  });

  return b.settings(settings);
});

```

but when i want to add the mapping or something else, isn't easier. i always need to use the Builder or the Lambda to add something. but i really want just edit the JSON String so i can really know what's i added and i can check template source.  
so guys,do u have any good idea about create a new PutComponentTemplateRequest?  
sorry for my terriable English and Tech, and thank you for listening.

---

<div class="post-metadata">

**Author:** ![black\_t](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/black_t/32/107643_2.png) [@black\_t](https://discuss.elastic.co/u/black_t)\
**Post date:** [June 29, 2022, 6:41am UTC](https://discuss.elastic.co/t/some-questions-about-putcomponenttemplaterequest-in-java-api/308308/2 "2022-06-29T06:41:12Z")

</div>

guys! helppppppp!!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 27, 2022, 6:41am UTC](https://discuss.elastic.co/t/some-questions-about-putcomponenttemplaterequest-in-java-api/308308/3 "2022-07-27T06:41:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
