Problems connecting to existing ElasticSearch instance in a spring boot application

I have an elasticsearch instance running locally.
I have a spring boot application.
In my application I have a service ServiceX which contains an elasticsearch repository which extends ElasticsearchRepository.
So
Service X contains
YRepository extends ElasticsearchRepository<Y, String>

I have an elasticsearch instance running locally.

My elastic search settings are

ELASTICSEARCH (ElasticsearchProperties)

spring.data.elasticsearch.properties.http.enabled=true
spring.data.elasticsearch.properties.host = localhost
spring.data.elasticsearch.properties.port = 9300

When the application is started an elasticsearch template is created.
The client that is used is a NodeClient.
The settings for the NodeClient are
"http.enabled" -> "true"
"port" -> "9300"
"host" -> "localhost"
"cluster.name" -> "elasticsearch"
"node.local" -> "true"
"name" -> "Human Robot"
"path.logs" -> "C:/dev/git/xxx/logs"

The name of the elasticsearch (Human Robot in this case), does not match the local elasticsearch instance running (Nikki in this case).

It looks like it

  1. creates a new instance of logstash
  2. creates an embedded instance of logstash.

I have searched through a lot of information but cannot find any documentation to help.

Could people please advise about what settings to use?
Thanks.

I found the solution

Create a configuration class and put a transfer client bean in there

@Configuration
public class ElasticSearchConfig {

@Bean
public Client client() {
    TransportClient client = new TransportClient();
    TransportAddress address = new InetSocketTransportAddress(
            "localhost",9300);
    client.addTransportAddress(address);
    return client;
}

}

Hi SKing,

This is a late reply. However, I think It might me useful for other users facing the same problem. With Spring boot we do NOT need to write our own configuration. we have to mention the Elaticsearch properties in application.properties as mentioned below:
#Elasticsearch Configuration spring.data.elasticsearch.cluster-name=<name of the cluster> spring.data.elasticsearch.cluster-nodes=localhost:9300 spring.data.elasticsearch.repositories.enabled=true

I have created one application on github. Please refer to below link
Spring Boot Elasticsearch

Also, we have to be careful about the version of Elasticsearch running locally and the version that is supported by Spring boot. They should match.

If you need further help. Please let me know, will be happy to help.

Hello @ahmadimt07,
Thanks for the information. Have you also tried using Spring data? I want to map the POJO to the elastic document.
Thanks

@SuperMohit Yes, I have used Spring Data Elasticsearch.

You can do that. If you are facing any issues, let us know or share a sample project for that.

Thank you for your help. Your second advise worked. I had installed 5.1.1 version while Boot only supports 2.4.3.

Glad to hear :slight_smile: