Springboot elastic search health management : ConnectException: Connection refused
Spring boot elasticsearch needs to know to which port (and host) to connect for the health check. Add:
spring:
elasticsearch:
rest:
uris: "myelasticserver:9200"
#username: ""
#password: ""
This is in addition to the config you already have. This is separate because many people, like me, use the (non-http) port 9300 of elasticsearch for the actual searches instead of your part of the config. I neither have management.health.elasticsearch. My total config for elasticsearch is:
spring:
elasticsearch:
rest:
uris: "myelasticserver:9200"
data:
elasticsearch:
cluster-nodes: "myelasticserver:9300"
cluster-name: "my-cluster-name"
The problem is indeed, as mst mentioned, that the actuator uses the RestClient
. If you have configured the RestHighLevelClient
, the configuration is not applied to the RestClient
.
If you already have the RestHighLevelClient
available, you can easily make a configured RestClient
available as follows:
@Bean(destroyMethod = "close")
public RestClient restClient() {
return restHighLevelClient().getLowLevelClient();
}