parent
a747c8cb65
commit
d513def487
@ -0,0 +1,41 @@
|
||||
package com.mashibing.search.config;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author heqijun
|
||||
* @ClassName: RestHighLevelClient
|
||||
* @Description: TODO(这里用一句话描述这个类的作用)
|
||||
* @date 2025/6/12 17:09
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class RestHighLevelClientConfig {
|
||||
|
||||
@Value("${elasticsearch.hostAndPorts}")
|
||||
private String[] hostAndPorts;
|
||||
|
||||
@Bean
|
||||
public RestHighLevelClient restHighLevelClient() {
|
||||
|
||||
HttpHost[] httpHost = new HttpHost[hostAndPorts.length];
|
||||
for (int i = 0; i < httpHost.length; i++) {
|
||||
String[] hostAndPort = hostAndPorts[i].split(":");
|
||||
httpHost[i] = new HttpHost(hostAndPort[0], Integer.parseInt(hostAndPort[1]));
|
||||
}
|
||||
|
||||
RestClientBuilder restClientBuilder = RestClient.builder(httpHost);
|
||||
|
||||
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
|
||||
|
||||
return restHighLevelClient;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue