gpt4 book ai didi

java - Elasticsearch 因 NoNodeAvailableException 而失败

转载 作者:行者123 更新时间:2023-11-29 02:57:34 31 4
gpt4 key购买 nike

我正在像这样运行 elasticsearch 图像:docker-compose.yml

version: '2'
services:
elasticsearch:
image: elasticsearch:5.4
ports:
- "9200:9200"
- "9300:9300"

我可以用 curl 检查它是否正在运行。

curl http://127.0.0.1:9200/_cluster/health

响应:

{"cluster_name":"elasticsearch","status":"green","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":0,"active_shards":0,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":0,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":0,"active_shards_percent_as_number":100.0}

在应用程序中,我这样配置 TransportClient:

@Bean(destroyMethod = "close")
public TransportClient transportClient() throws UnknownHostException {
return new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByName("localhost"), 9300));
}

然后我想检查一下:

@Autowired
private TransportClient client;
@GetMapping(value = "test")
public Object test(){
return client.admin().cluster().health(Requests
.clusterHealthRequest())
.actionGet();
}

但它失败了:

org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{_atMOwK5R5mgOXqAPJWvWg}{localhost}{127.0.0.1:9300}]

顺便说一句,我正在使用这个依赖项:compile('org.elasticsearch.client:transport:5.4.0')

最佳答案

尝试提供 elasticsearch 而不是本地主机,因为这是您的容器名称,以防 spring boot 应用程序也在 docker 中运行

关于java - Elasticsearch 因 NoNodeAvailableException 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44286937/

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