本机项目访问阿里云部署的elasticsearch服务报错: None of the configured nodes are available: [{#transport#-1}

 去网上查了好多资料,最后在下面这个博客中受到启发

https://blog.csdn.net/demon_LL/article/details/56852960

 如果设置client.transport.sniff为true,则表示客户端去嗅探整个cluster的状态,把集群中其它机器的ip地址加到客户端中

我想我已经配置了节点ip,为什么还要去"嗅探",抱着试一试的态度把这个配置给注释掉, 然后就 ok了

package com.imooc.config;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 邵少
 * @date 2019年5月26日
 */
@Configuration
public class ElasticSearchConfig {
	
	@Bean
	public TransportClient esClient() throws UnknownHostException{
		Settings settings = Settings.builder()
				.put("cluster.name", "elasticsearch")
//				.put("client.transport.sniff", true) // 自动发现节点
				.build();
				
		InetSocketTransportAddress master = new InetSocketTransportAddress(
				InetAddress.getByName("46.105.210.100"),9300
				);
		
		TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(master);
		return client;
	}
}

把这行配置注释掉

其实一开始我是访问本机部署的elasticsearch, 由于占用资源太多, 导致电脑太卡 , 就买了台阿里云服务器, 在阿里云服务器部署了elasticsearch服务, 想在本机访问 ,遇到了这个问题  

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值