How to connect to docker instance of elasticsearch

I have used elastic search(rest high level client) in spring boot. The local instance of my computer running fine. But, when I am trying to access the azure vm docker instance I can't able to use. I can able to get json file when hitting ideas.cloudapp.azure.com(let say the host name) ideas.cloudapp.azure.com:9200. And I am using mentioed cluster name in that json in my spring boot application
spring.data.elasticsearch.cluster-name = docker-cluster

And I set the
spring.data.elasticsearch.cluster-nodes = ideas.cloudapp.azure.com:9300
In docker I have 2 port running 9200 and 9300 having same port for outside container

And I ran my program which was giving error. Then I opened my laptop's localhost instance and kept the cluster node sam and it ran but was not storing in docker instance. Later, found out it is uisng laptop's local instance, then I gave random cluster-nodes. For which also it toop laptop's local instance

And, in docker logs for es container there is no log of connected, index created, delted, or data inserted nothing.

And when I turned off local instance of laptop and ran. Still it is pointing to local instance

Caused by: java.net.ConnectException: Timeout connecting to [localhost/127.0.0.1:9200]

I tried debugging but when it went out of spring boot to elastic search files, it showed "source file not found". So, I can't able to debug properly

What to do?

Not sure what you did. It's probably a Spring data elasticsearch concern or you did not open your Azure cluster to the machine where your application is running.

Did you read BTW https://docs.spring.io/spring-data/elasticsearch/docs/3.2.0.M1/reference/html/#elasticsearch.clients.rest ? Are you sure that setting spring.data.elasticsearch.cluster-nodes sets the nodes for elasticsearch client?

You should first try to run from your machine where the app is running:

curl ideas.cloudapp.azure.com:9200

If it works well, then you need to solve the problem on spring data side.
If it does not work, then probably your Azure 9200 port is not opened for your machine.

But please don't expose your 9200 port to internet. At least not without any security layer.

Hi,
By default it was connecting to localhost:9200, not to my docker based.
After giving this in application.properties it worked

spring.elasticsearch.rest.uris = http://ideas.cloudapp.azure.com:9200

Before, that it can not able to point, so I think by default it was pointing to localhost

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