The current java API for elastic search documentation does not say anything about creating an index template. I know I can create an index template using crud, but my elastic search index is going grow depending on the data I get. The data I have right now, it may be possible that the data may change. So instead of manually making an index and a template, I want to know if it can be done through writing a code in Java.
1 Answer
You can use the IndicesAdminClient to create a template
node.client().admin().indices().putTemplate(
new PutIndexTemplateRequest("templatename").source(templateString)
);
PutIndexTemplateRequest has other methods to programatically build the template if you'd prefer to build it as a Java map, etc.
2 Comments
Vikash
Is an index template created at Node level or cluster level?
Andrew Rueckert
@Vikash an index template is distinct from both cluster-settings and node-settings. You could consider it cluster-level, because it applies to all indices created in the cluster. elastic.co/guide/en/elasticsearch/reference/current/…