Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 523
sohil Avatar asked Jun 20 '16 22:06

sohil


People also ask

How do I create an index in Elasticsearch?

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.

What is an index template Elasticsearch?

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.

How do I create an index template in Kibana?

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.

How do I create an index in Elasticsearch using curl?

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.


1 Answers

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.

like image 65
Andrew Rueckert Avatar answered Oct 03 '22 16:10

Andrew Rueckert