Templates w/ new java-client

Initially I was looking for a way to add component and index templates via the new java-client. Then I stumbled upon the following two methods:

  • ElasticsearchIndicesClient.getTemplate
  • ElasticsearchIndicesClient.getIndexTemplate

both of their documentation links send me to the the Index-Template page.

Can you explain the difference of those two methods?

Anyhow, the component template is defined in the cluster namespace.

Back to my main problem: With the HLRC I was able to read a JSON from disk, defining the component or index template. But I can't seem to find it. In one Test I found this method - is this the preferred way?


The getTemplate method is for the "legacy index template" API. Thanks for the report, we will fix the link.

Regarding loading JSON from disk, this is indeed a way to do it. Be aware though that it may not work for requests that have a required path parameter, such as index creation. We have recently added a feature that allows reading any object from JSON and will be in the next minor releases.

Pull request: Raw json support by swallez · Pull Request #200 · elastic/elasticsearch-java · GitHub
Docs: Creating API objects from JSON data | Elasticsearch Java API Client [master] | Elastic

Perfect, and happy to help!.

I read the second link, but I need it for the IndexTemplate and ComponentTemplate to read from JSON, so I guess the pull request, if this includes those configuration classes, should be perfect.

I'll go w/ the way in the Test class for now, and switch to the other one as soon as it's available.


if this includes those configuration classes, should be perfect

Yep, it does :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.