[AppleScript] 纯文本查看 复制代码
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; @Configuration public class ElasticsearchConfig {
@Value("${xuecheng.elasticsearch.hostlist}")
private String hostlist;
@Bean
public RestHighLevelClient restHighLevelClient(){
//解析hostlist配置信息
String[] split = hostlist.split(",");
//创建HttpHost数组,其中存放es主机和端口的配置信息
HttpHost[] httpHostArray = new HttpHost[split.length];
for(int i=0;i<split.length;i++){
String item = split;
httpHostArray = new HttpHost(item.split(":")[0], Integer.parseInt(item.split(":") [1]), "http");
}
//创建RestHighLevelClient客户端
return new RestHighLevelClient(RestClient.builder(httpHostArray));
}
@Bean public RestClient restClient(){
//解析hostlist配置信息
String[] split = hostlist.split(",");
//创建HttpHost数组,其中存放es主机和端口的配置信息
HttpHost[] httpHostArray = new HttpHost[split.length];
for(int i=0;i<split.length;i++){
String item = split;
httpHostArray = new HttpHost(item.split(":")[0], Integer.parseInt(item.split(":") [1]), "http");
}
return RestClient.builder(httpHostArray).build();
} }