javaspringelasticsearchelasticsearch-rest-client

using elasticsearchoperations vs elasticsearchtemplate whats the difference?


I am trying to figure out why I have to set my bean name to elasticsearchTemplate. Without it, my application crashes. I have the code below to configure my Rest client. The issue is if I don't add the elasticsearchTemplate as the bean name, it fails and says it cannot find elasticsearchTemplate. Any idea on why it does this and also what is the difference of using elasticsearchoperations vs elasticsearchtemplate?

Using Spring-Data-Elasticsearch Version 3.2
Using Java High-Level Rest Client Version 6.8.0

Works

@Bean("elasticsearchtemplate")
public ElasticsearchOperations elasticsearchTemplate() throws Exception {
    return new ElasticsearchTemplate(client());
}

Doesn't Work

public ElasticsearchOperations elasticsearchTemplate() throws Exception {
    return new ElasticsearchTemplate(client());
}

Solution

  • Maybe because the startup configuration (application.properties) is missing the configuration related to elasticsearch. You need to define some elastic search properties in your application.properties file such as cluster-nodes, cluster-names which are used by ElasticsearchTemplate and ElasticsearchRepository to connect to the Elasticsearch engine. as follows