Connect to elasticsearch 6.4 running in Docker from golang host application

456 views Asked by At

Go ES client https://godoc.org/gopkg.in/olivere/elastic.v6 throws the "no active connection found: no Elasticsearch node available" error when attempting to connect from OS X host to ES running in docker container. There's many discussions on how to solve it in v5.*, however, I couldn't find anything for v6.4.

Docker-compose part:

elasticsearch:
    image: elasticsearch:6.4.2
    network_mode: "bridge"
    expose:
      - "9200"
      - "9300"
    volumes:
      - ./es-data:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"
      - "9300:9300"

Go client call:

esClient, esClientErr :=             
elastic.NewClient(elastic.SetURL("http://127.0.0.1:9200"))
if esClientErr != nil {
    return nil, fmt.Errorf("Failed to connect to ES: %v", esClientErr)
}

Output:

2018/11/09 15:57:54 Failed to connect to ES: no active connection found: no Elasticsearch node available
exit status 1

UPDATE

Setting network.publish_host: "_local_" solved the problem. The publish_address is set to 127.0.0.1:9300 now.

0

There are 0 answers