工程基础配置完成
This commit is contained in:
@@ -1,9 +1,41 @@
|
||||
package top.fjy8018.elasticsearch.configeration;
|
||||
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* @author F嘉阳
|
||||
* @date 2018-05-19 12:22
|
||||
*/
|
||||
@Configuration
|
||||
public class ElasticSearchConfiger {
|
||||
|
||||
/**
|
||||
* 创建连接客户端
|
||||
* @return
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
@Bean
|
||||
public TransportClient client() throws UnknownHostException {
|
||||
// 构造连接地址,TCP地址和端口
|
||||
TransportAddress node = new TransportAddress(InetAddress.getByName("192.168.79.138"), 9300);
|
||||
|
||||
// 初始化自定义配置,若和主节点名字不一致则会无法连接
|
||||
Settings settings = Settings.builder().put("cluster.name", "Fjiayang").build();
|
||||
|
||||
// 构造连接实例
|
||||
TransportClient client = new PreBuiltTransportClient(settings);
|
||||
|
||||
client.addTransportAddress(node);
|
||||
|
||||
return client;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user