0

I have a spring boot application which uses elasticsearch db and mongodb. I want to dockerize this on a docker-container for which I have written a docker-compose yml file which is given below

version : "3"
services:
  eswmongodb:
   image: mongo:latest
   container_name: mongocont
   ports:
    - "27017:27017"

  elasticsearch:
   image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
   container_name: elasticsearch
   environment:
    - node.name=elasticsearch
    - discovery.type=single-node
    - cluster.name=docker-cluster
   ports:
    - "9200:9200"
    - "9300:9300"


 esw:
  image: esw
  container_name: eswrapper
  ports:
    - "8071:8071"
  links:
    - elasticsearch
    - eswmongodb

Only mongodb is getting connected with the spring boot application and I am able to access that but when I am hitting an api which uses a elasticsearch. I get an error as

Occurred with exception:[Connection refused]

java.net.ConnectException: Connection refused

I have supplied the necessary information in application.properties file.

spring.data.elasticsearch.cluster-node=elasticsearch:9200
spring.data.elasticsearch.cluster-name=docker-cluster
spring.data.mongodb.uri=mongodb://eswmongodb:27017/esw

Any thoughts why elasticsearch is not able to get connected. I have seen earlier answers provided in stack-overflow but the issue still persists.

All container are showing running.

Also tried spring.data.elasticsearch.cluster-nodes this property but this becomes disable so I went with spring.data.elasticsearch.cluster-node.

I have also added the actual exception present in logs when I hit an api endpoint which uses elastic search for further help if required.

2022-01-04 13:44:45,354 | ERROR | TxId=1641303885129000010435 | 
IndexOperationsImpl.createIndexWithCustomSettingAndMapping:62 | 
Exception Occurred with exception:[Connection refused]

java.net.ConnectException: Connection refused at 

org.elasticsearch.client.RestClient.
extractAndWrapCause(RestClient.java:849)

at  org.elasticsearch.client.RestClient.
performRequest(RestClient.java:259)

at org.elasticsearch.client.RestClient.
performRequest(RestClient.java:246)

Some logs of elasticsearch container when hitting docker-compose logs elasticsearch

Attaching to elasticsearch
elasticsearch    | {"type": "server", "timestamp": "2022-01- 
04T16:03:59,187Z", "level": "INFO", "component": "o.e.n.Node", 
"cluster.name": "docker-cluster", "node.name": "elasticsearch", 
"message": "version[7.9.3], pid[7], 
[default/docker/c4138e51121ef06a6404866cddc601906fe5c868/2020 
10-16T13:34:25.304557Z], OS[Linux/5.10.25-linuxkit/aarch64], 
JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/15/15+36-1562]" }
elasticsearch    | {"type": "server", "timestamp": "2022-01- 
04T16:03:59,189Z", "level": "INFO", "component": "o.e.n.Node", 
"cluster.name": "docker-cluster", "node.name": "elasticsearch", 
"message": "JVM home [/usr/share/elasticsearch/jdk]" }
12
  • 1
    Can you paste the output of "docker-compose logs elasticsearch" to your question? If there was error in the log, you can paste just the error will do. Commented Jan 4, 2022 at 14:18
  • That smells like a dead elastic container right after start. Commented Jan 4, 2022 at 14:38
  • 1
    links: is an obsolete and unnecessary Compose option, and it might interfere with the networking setup. Does removing the links: block (or changing it to depends_on:) help? Is the application starting up before Elasticsearch is available? Commented Jan 4, 2022 at 14:43
  • yes application is running but only with mongodb, if I hit for an api which uses elastic search it says connection refused Commented Jan 4, 2022 at 15:47
  • 1
    @gohm'c, there are lot of logs. so added some part in the question. Commented Jan 4, 2022 at 16:51

1 Answer 1

1

Solved it by providing spring.data.elasticsearch.cluster-nodes in application.yml instead of application.properties file. It may sound strange but don't know why it is disabled in properties file but works in yml file as provided below.

spring:
  data:
    elasticsearch:
      cluster-name: docker-cluster
      cluster-nodes: elasticsearch:9200

Anyway thanks for providing suggestions in comment section of the question

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.