RestClientConfig AbstractElasticsearchConfiguration connect to docker service on same network

I am using spring data elasticsearch to connect to elasticesearch in a docker container. The code i use can be found here under

  1. High Level REST Client

https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#reference

static class Config {

  @Bean
  RestHighLevelClient client() {

    ClientConfiguration clientConfiguration = ClientConfiguration.builder() 
      .connectedTo("elasticsearch")
      .build();

    return RestClients.create(clientConfiguration).rest();                  
  }
}

The spring boot app and the docker elastic search is on the same network because they are both in the same directoy (Both spring boot docker-compose and elasticsearch docker-compose file).

My elasticsearch docker-compose is as such

version: ‘3’

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.8.6
    container_name: elasticsearch
    environment:
      - cluster.name=cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - ./config/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/elasticsearch.yml
      - esdata6:/usr/share/elasticsearch/data    
    ports:
      - "9200:9200"
  kibana:
    image: docker.elastic.co/kibana/kibana:6.8.6
    container_name: kibana
    volumes:
      - ./config/kibana/kibana.yml:/usr/share/kibana/kibana.yml
    restart: on-failure
    ports:
      - "5601:5601"

volumes:
  esdata6:

I am getting the error

Caused by: java.io.IOException: elasticsearch
Caused by: java.net.UnknownHostException: elasticsearch

How can i let my spring boot see the elasticsearch service name and resolve it? I think it is something to do with the RestClients.

Source: StackOverflow