Gitlab CI connection refused on elasticsearch

I try to connect elasticsearch on Gitlab CI for running my test but always got connection refused

here my script

services:
      - name: docker.elastic.co/elasticsearch/elasticsearch:7.6.0          
        command: [ "bin/elasticsearch", "-Expack.security.enabled=false", "-Ediscovery.type=single-node" ]
script:
      - curl "http://$(cat /etc/hosts |grep $HOSTNAME|cut -d$'t' -f1):9200"

Wtih $(cat /etc/hosts |grep $HOSTNAME|cut -d$'t' -f1) I can get IP address

I try to use alias: elasticsearch but when I curl "http://elasticsearch:9200" also got error Could not resolve host

Source: StackOverflow