org.springframework.data.elasticsearch.client.TransportClientFactoryBean Java Examples
The following examples show how to use
org.springframework.data.elasticsearch.client.TransportClientFactoryBean.
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 |
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: ElasticDataConfig.java From Spring-5.0-Projects with MIT License | 5 votes |
@Bean public Client client() throws Exception { /*Settings esSettings = Settings.builder() .put("cluster.name", esClusterName) .build();*/ //https://www.elastic.co/guide/en/elasticsearch/guide/current/_transport_client_versus_node_client.html TransportClientFactoryBean transportClientFactory = new TransportClientFactoryBean(); transportClientFactory.setClusterName(esClusterName); transportClientFactory.afterPropertiesSet(); return transportClientFactory.getObject() .addTransportAddress( new TransportAddress(InetAddress.getByName(esHost), esPort)); }
Example #3
Source File: ElasticsearchSpringFactory.java From database-transform-tool with Apache License 2.0 | 5 votes |
/** * 描述: 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); } }