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 and follow it to create :
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 :
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.