# Problems connecting to existing ElasticSearch instance in a spring boot application

**URL:** <https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805>\
**Category:** Elasticsearch\
**Created:** [March 8, 2016, 4:31pm UTC](https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805 "2016-03-08T16:31:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SKing](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@SKing](https://discuss.elastic.co/u/SKing)\
**Post date:** [March 8, 2016, 4:31pm UTC](https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805/1 "2016-03-08T16:31:41Z")

</div>

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](http://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.

---

<div class="post-metadata">

**Author:** ![SKing](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@SKing](https://discuss.elastic.co/u/SKing)\
**Post date:** [March 9, 2016, 2:53pm UTC](https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805/2 "2016-03-09T14:53:38Z")

</div>

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;
}

```

}

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [May 31, 2016, 1:37am UTC](https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805/3 "2016-05-31T01:37:50Z")

</div>

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](http://ahmadimt.github.io/springbootes/)

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.

---

<div class="post-metadata">

**Author:** ![SuperMohit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/supermohit/32/14242_2.png) [@SuperMohit](https://discuss.elastic.co/u/SuperMohit)\
**Post date:** [January 2, 2017, 6:04am UTC](https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805/4 "2017-01-02T06:04:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [January 2, 2017, 7:07am UTC](https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805/5 "2017-01-02T07:07:52Z")

</div>

@SuperMohit Yes, I have used Spring Data Elasticsearch.

> [@SuperMohit](#):
>
> I want to map the POJO to the elastic document.

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

---

<div class="post-metadata">

**Author:** ![SuperMohit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/supermohit/32/14242_2.png) [@SuperMohit](https://discuss.elastic.co/u/SuperMohit)\
**Post date:** [January 3, 2017, 3:27am UTC](https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805/6 "2017-01-03T03:27:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [January 3, 2017, 1:43pm UTC](https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805/7 "2017-01-03T13:43:46Z")

</div>

Glad to hear 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:04pm UTC](https://discuss.elastic.co/t/problems-connecting-to-existing-elasticsearch-instance-in-a-spring-boot-application/43805/8 "2017-07-05T22:04:31Z")

</div>


