# Elasticsearch with Go and Docker

**URL:** <https://discuss.elastic.co/t/elasticsearch-with-go-and-docker/305008>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [May 18, 2022, 2:03am UTC](https://discuss.elastic.co/t/elasticsearch-with-go-and-docker/305008 "2022-05-18T02:03:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrfirdauss-20](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrfirdauss-20/32/97650_2.png) [@mrfirdauss-20](https://discuss.elastic.co/u/mrfirdauss-20)\
**Post date:** [May 18, 2022, 2:03am UTC](https://discuss.elastic.co/t/elasticsearch-with-go-and-docker/305008/1 "2022-05-18T02:03:37Z")

</div>

I use docker and Elasticsearch, i got confused, when i set the Elasticsearch url (when initialize it) in golang to "Elasticsearch:9200", the massages shows

`> "health check timeout: no Elasticsearch node available"`

but if i dont set anything the messages shows

```auto

: Head "http://127.0.0.1:9200": dial tcp 127.0.0.1:9200: connect: connection refused: no Elasticsearch node available

```

i dont know how to initialize data via .sh, json file, and connect it to golang for Elasticsearch. I have done some research for many dayt, but i still confused.  
here is the yml file

```auto
version: '2.4'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
    healthcheck:
      test: "curl http://elasticsearch:9200/_cluster/health"
    environment:
      - xpack.security.enabled=false
      - discovery.type=single-node
      - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9201:9200"
  elasticsearch_seeder:
    build:
      context: ../../
      dockerfile: ./build/package/seeder/Dockerfile
    image: curlimages/curl:7.82.0
    depends_on:
      elasticsearch:
        condition: service_healthy
    command: sh -c "/elasticsearch_init.sh"
    volumes:
      - ./elasticsearch_init.sh:/elasticsearch_init.sh
      - ./data.json:/data.json

```

and here is the .sh file

```auto

ES_HOST=elasticsearch:9200

curl -s -XPUT $ES_HOST/comics \
    -H "Content-Type: application/json" \
    -d '
    {
        "mappings": {
            "dynamic": false,
            "properties": {
                "title": {
                    "type": "text"
                },
                "images":{
                    "type": "nested"
                }
            }
        },
        "settings": {   
            "analysis": {
                "analyzer": {
                    "default": {
                        "type": "standard",
                        "stopwords": "_english_"
                    }
                }
            }
        }
    }
'

```

they are in a folder with data.json, which contain data for Elasticsearch.

this is how i initialize the Elasticsearch client in golang

```auto
config, err := elastic.NewClient(elastic.SetURL("elasticsearch:9200"))

```

im using "[GitHub - olivere/elastic: Elasticsearch client for Go.](http://github.com/olivere/elastic)"

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 18, 2022, 2:19am UTC](https://discuss.elastic.co/t/elasticsearch-with-go-and-docker/305008/2 "2022-05-18T02:19:32Z")

</div>

Welcome to our community! 😃

It'd be helpful if you showed us your docker file.

---

<div class="post-metadata">

**Author:** ![mrfirdauss-20](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrfirdauss-20/32/97650_2.png) [@mrfirdauss-20](https://discuss.elastic.co/u/mrfirdauss-20)\
**Post date:** [May 18, 2022, 4:21am UTC](https://discuss.elastic.co/t/elasticsearch-with-go-and-docker/305008/3 "2022-05-18T04:21:43Z")

</div>

heloo, i have updated the question, any other request? thank you for responding my question

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 15, 2022, 4:21am UTC](https://discuss.elastic.co/t/elasticsearch-with-go-and-docker/305008/4 "2022-06-15T04:21:54Z")

</div>

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