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.
To create an index, all you have to do is pass the index name without other parameters, which creates an index using default settings. You can also specify various features of the index, such as in the index body: The settings for the index.
An index template is a way to tell Elasticsearch how to configure an index when it is created. For data streams, the index template configures the stream's backing indices as they are created. Templates are configured prior to index creation.
Open the Kibana UI and go to the Management page. On the Management page, you will see the list of all the indices and the index templates. Click on the Index Template tab and you will see the index templates and you can also create a new template using the Create a Template option.
The other way is to do an SSH into one of the nodes in your cluster and run the POST command using CURL. I will automatically create an index named 'bookindex' with type 'books' and index the data. If index and type already exist it will add the entry to the index. Show activity on this post.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With