Elasticsearch with Go and Docker

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


: 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

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


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

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

im using "GitHub - olivere/elastic: Elasticsearch client for Go."

Welcome to our community! :smiley:

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

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

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