package com.zhiwei.manage.util;

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;

/**
 * es连接类
 * 
 * @author shenjinzhu
 *
 */
public class ESClient {
	static TransportClient client=null;
	
	public ESClient(String clusterName,String esIp,int esPort) {
		Settings esSettings = Settings.builder().put("cluster.name", clusterName) // 设置ES实例的名称
				.put("client.transport.sniff", false).build();
		client = new PreBuiltTransportClient(esSettings);
		try {
			client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(esIp), esPort));
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
	}
	
	public TransportClient getClient() {
		return client;
	}

}
