I am running elasticsearch image like this: docker-compose.yml
version: '2'
services:
elasticsearch:
image: elasticsearch:5.4
ports:
- "9200:9200"
- "9300:9300"
I can check it is running with curl.
curl http://127.0.0.1:9200/_cluster/health
Response:
{"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}
In application I configure TransportClient like this:
@Bean(destroyMethod = "close")
public TransportClient transportClient() throws UnknownHostException {
return new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByName("localhost"), 9300));
}
And then I want to check it:
@Autowired
private TransportClient client;
@GetMapping(value = "test")
public Object test(){
return client.admin().cluster().health(Requests
.clusterHealthRequest())
.actionGet();
}
but it fails with exception:
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{_atMOwK5R5mgOXqAPJWvWg}{localhost}{127.0.0.1:9300}]
BTW I am using this dependency: compile('org.elasticsearch.client:transport:5.4.0')
而不是本地主机尝试提供elasticsearch,因为这是您的容器名称,以防spring Boot应用程序也在docker中运行
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.