【问题标题】:Can't connect to elasticsearch on port 9300 in docker无法连接到 docker 中端口 9300 上的 elasticsearch
【发布时间】:2018-03-29 07:56:01
【问题描述】:

我正在本地机器上通过 docker 运行 elasticsearch,并且可以通过端口 9200 上的 REST API 正常访问它。

Apache flink 用于通过端口 9300 与 elasticsearch 通信。

我的目标是通过接收器将数据从 apache flink 放到 elasticsearch,但是在每次执行我的程序时,我都会收到 java 错误:

Elasticsearch client is not connected to any Elasticsearch nodes!

我运行容器的 docker 命令如下所示:

docker run --rm -d -p 9200:9200 -p 9300:9300 -p 5601:5601 --name es-kibana nshou/elasticsearch-kibana

我还尝试通过“-p 0.0.0.0:9300:9300”打开端口 9300 或使用官方 docker 容器进行弹性搜索。

是否有人也遇到过这个问题并有解决方案?接下来我想尝试的是在我的机器上本地安装elasticsearch,但我认为docker方式更有价值。

这里也是我的flink代码以及elasticsearch中索引和映射的创建:

List<InetSocketAddress> transports = new ArrayList<>();
    transports.add(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 9300));

    tweets.addSink(new ElasticsearchSink<Tuple2<String, Integer>>(
            config,
            transports,
            new ESSink()));

用于索引 ES 的卷曲:

curl --request PUT --url http://localhost:9200/twitter-bd

用于映射 ES 的 curl:

curl --request PUT 
--url http://localhost:9200/twitter-bd/_mapping/twitter-wordcount \
--header 'content-type: application/json' \
--data '{
    "twitter-wordcount": {
        "properties": {
            "word": {"type": "string"},
            "cnt": {"type": "integer"}
        }
     }
}'

【问题讨论】:

  • 从你的主机上,elasticsearch 在 localhost:9300 上可用,也许你应该将地址更改为 localhost:transports.add(new InetSocketAddress(InetAddress.getByName("localhost"), 9300));

标签: docker elasticsearch apache-flink


【解决方案1】:

创建一个 docker-compose 文件 docker-compose.yml

version: '2'
services:
    elasticsearch:
        container_name: elasticsearch
        image: elasticsearch:2.4.1
        # UNCOMMENT BELOW LINES TO HAVE PERSISTAN STORAGE
        # volumes:
        #     - /var/db/elasticsearch/:/usr/share/elasticsearch/data/
        ports:
            - 9200:9200
            - 9300:9300

运行

docker-compose up -d

使用 9300 端口与 ES 通信

创建内容

curl -XPUT "http://localhost:9200/playground/equipment/1" -d ' { "type": "slide", "quantity": 2 }'

阅读内容

curl -XGET "http://localhost:9200/playground/equipment/1"

How To Interact with Data in ElasticSearch Using CRUD Operations

【讨论】:

  • 非常感谢,这很好用!你知道为什么这在我以前的方法中不起作用吗?乍一看,我看到的唯一区别是较低版本的 ES...
  • beeter 始终使用默认图像。你为什么使用 teh nshou/elasticsearch-kibana ?我们需要检查他们的容器配置。你能接受这个作为答案吗
  • 我也尝试过最新版本。它工作正常。
猜你喜欢
  • 1970-01-01
  • 2021-04-16
  • 2019-03-11
  • 1970-01-01
  • 2017-03-13
  • 2019-10-25
  • 2020-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多