Elasticsearch全文检索连接问题
Caused by: java.lang.RuntimeException: Connection is closed at
org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.translateException
(ElasticsearchRestTemplate.java:425) ~[spring-data-elasticsearch-4.3.2.jar:4.3.2] ...
54 common frames omitted
大概就是说:连接已在org.springframework.data.elasticsearch.core处被关闭。
个人觉得是长时间没使用导致连接断开。
解决方法
在elasticsearch配置类加上长连接文章来源:https://www.toymoban.com/news/detail-503583.html
.setHttpClientConfigCallback(httpClientBuilder ->{
httpClientBuilder.setKeepAliveStrategy(((httpResponse, httpContext) -> Duration.ofMinutes(3).toMillis()));
httpClientBuilder.disableAuthCaching();
return httpClientBuilder;
这是我完整的配置类:文章来源地址https://www.toymoban.com/news/detail-503583.html
@Component
@ConfigurationProperties("es")
@Data
public class ESConfig {
@Value("${es.ip}")
private String ip;
@Value("${es.port}")
private int port;
@Bean
public RestHighLevelClient restHighLevelClient(){
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost(ip,port,"http")
)
//配置长连接setHttpClientConfigCallback 默认 net.ipv4.tcp_keepalive_time = 7200s
.setHttpClientConfigCallback(httpClientBuilder ->{
httpClientBuilder.setKeepAliveStrategy(((httpResponse, httpContext) -> Duration.ofMinutes(3).toMillis()));
httpClientBuilder.disableAuthCaching();
// httpClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom()
// .setSoKeepAlive(true)
// .build());
return httpClientBuilder;
})
);
return client;
}
}
到了这里,关于Elasticsearch Connection is closed全文检索连接问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!