dongyuan1984 2018-11-09 15:09
浏览 215

从golang主机应用程序连接到Docker中运行的Elasticsearch 6.4

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧