...
|
...
|
@@ -3,6 +3,7 @@ package com.sunyo.wlpt.message.bus.service.config; |
|
|
import org.apache.http.HttpHost;
|
|
|
import org.elasticsearch.client.RestClient;
|
|
|
import org.elasticsearch.client.RestHighLevelClient;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
|
...
|
...
|
@@ -16,23 +17,24 @@ import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; |
|
|
@Configuration
|
|
|
public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {
|
|
|
|
|
|
|
|
|
@Value("${es.hostname}")
|
|
|
private String hostname;
|
|
|
|
|
|
@Value("${es.port}")
|
|
|
private Integer port;
|
|
|
|
|
|
@Value("${es.scheme}")
|
|
|
private String scheme;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@Bean
|
|
|
|
|
|
public RestHighLevelClient elasticsearchClient()
|
|
|
{
|
|
|
RestHighLevelClient client = new RestHighLevelClient(
|
|
|
RestClient.builder(
|
|
|
// 天生契合集群,有几个es环境,就 new HttpHost 几个,用,相隔
|
|
|
new HttpHost("192.168.37.139", 9200, "http")
|
|
|
new HttpHost(hostname, port, scheme)
|
|
|
)
|
|
|
);
|
|
|
return client;
|
...
|
...
|
|