sohil
sohil

Reputation: 415

create an index template using the java api in elastic search

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.

Upvotes: 8

Views: 3506

Answers (1)

Andrew Rueckert
Andrew Rueckert

Reputation: 5215

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.

Upvotes: 10

Related Questions