我正在运行这样的elasticsearch图像: 搬运工-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}]
BTW我正在使用这种依赖:compile('org.elasticsearch.client:transport:5.4.0')
答案 0 :(得分:0)
而不是本地主机尝试提供elasticsearch,因为这是您的容器名称,以防Spring引导应用程序也在docker中运行