Java Code Examples for org.springframework.data.elasticsearch.client.TransportClientFactoryBean#setProperties()

The following examples show how to use org.springframework.data.elasticsearch.client.TransportClientFactoryBean#setProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeihuMutilElasticsearchAutoConfiguration.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
public TransportClient elasticsearchClient(BeihuMutilElasticsearchProperties.Instances instance) throws Exception {
    TransportClientFactoryBean factory = new TransportClientFactoryBean();
    factory.setClusterNodes(instance.getClusterNodes());
    factory.setProperties(this.createProperties(instance));
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example 2
Source File: ElasticsearchSpringFactory.java    From database-transform-tool with Apache License 2.0 5 votes vote down vote up
/**
 * 描述: Elasticsearch服务初始化
 * 时间: 2017年11月14日 上午10:55:02
 * @author yi.zhang
 */
public void init(String clusterName,String servers,String username,String password){
	try {
		TransportClientFactoryBean client = new TransportClientFactoryBean();
		client.setClusterName(clusterName);
		String clusterNodes = "";
		for(String server : servers.split(",")){
			String[] address = server.split(":");
			String ip = address[0];
			int port=9300;
			if(address.length>1){
				port = Integer.valueOf(address[1]);
			}
			if(StringUtil.isEmpty(clusterNodes)){
				clusterNodes = ip+":"+port;
			}else{
				clusterNodes +=","+ ip+":"+port;
			}
		}
		client.setClusterNodes(clusterNodes);
		if(!StringUtil.isEmpty(username)&&!StringUtil.isEmpty(password)){
			Properties properties = new Properties();
			properties.put("xpack.security.user",username+":"+password);
			client.setProperties(properties);
		}
		client.afterPropertiesSet();
		template = new ElasticsearchTemplate(client.getObject());
	} catch (Exception e) {
		logger.error("-----Elasticsearch Config init Error-----", e);
	}
}