gpt4 book ai didi

docker - 无法连接到 docker 中端口9300上的Elasticsearch

转载 作者:行者123 更新时间:2023-12-02 19:34:49 25 4
gpt4 key购买 nike

我正在本地计算机上通过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。

是否有人也遇到这个问题并有解决方案?我想尝试的下一件事是在我的机器上本地安装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:
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"}
}
}
}'

最佳答案

创建一个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

RUN

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

关于docker - 无法连接到 docker 中端口9300上的Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46793285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com