8

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 1

10

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Is an index template created at Node level or cluster level?
@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/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.