因为客户是政府项目,端口要开放策略
所有采用用nginx反代es
因为连接后面多了一个/es/
# es 配置
elasticsearch:
userName: elastic
password: DrnFCKEAgsMNMSMH
hosts: 10.68.182.147:80
scheme: http
connectTimeOut: 1000
socketTimeOut: 30000
connectionRequestTimeOut: 500
maxConnectNum: 100
maxConnectNumPerRoute: 100
#nginx反代的目录
contextPath: /es/
所有创建连接这里要改为
/**
* 如果@Bean没有指定bean的名称,那么方法名就是bean的名称
*/
@Bean(name = "restHighLevelClient")
public RestHighLevelClient restHighLevelClient() {
// 构建连接对象
RestClientBuilder builder = RestClient.builder(getEsHost());
//这里就是nginx配置的反代目录 /es/
if (StringUtils.isNotBlank(contextPath)) {
builder.setPathPrefix(contextPath);
}
// 连接延时配置
builder.setRequestConfigCallback(requestConfigBuilder -> {
requestConfigBuilder.setConnectTimeout(connectTimeOut);
requestConfigBuilder.setSocketTimeout(socketTimeOut);
requestConfigBuilder.setConnectionRequestTimeout(connectionRequestTimeOut);
return requestConfigBuilder;
});
// 连接数配置
builder.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.setMaxConnTotal(maxConnectNum);
httpClientBuilder.setMaxConnPerRoute(maxConnectNumPerRoute);
httpClientBuilder.setDefaultCredentialsProvider(getCredentialsProvider());
return httpClientBuilder;
});
return new RestHighLevelClient(builder);
}