Elasticsearch RestHighLevelClient SocketTimeoutException

时间:2019-09-26 07:24:16

标签: java spring spring-boot elasticsearch

我在Azure上安装了ES群集,并使用Elasticsearch RestHighLevelClient从Spring Boot应用程序与其进行通信。

春天的豆子紧随其后

@Bean
public RestHighLevelClient elasticsearchRestClient() {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(ipAddress, port))
            .setRequestConfigCallback(builder -> builder.setConnectTimeout(10000).setSocketTimeout(90000))
            .setHttpClientConfigCallback(httpAsyncClientBuilder ->
                    httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
    RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
    Sniffer sniffer = Sniffer.builder(restHighLevelClient.getLowLevelClient()).setSniffIntervalMillis(60000).build();
    return restHighLevelClient;
}

此处ipAddress是Azure ES群集上的loadbalancer的ip,端口为9200。 问题是-如果ES空闲了几分钟-对ES的下一个请求将失败,并出现SocketTimeoutException。

  

2019-09-26T07:20:50.228101050Z:[INFO]   java.net.SocketTimeoutException:90,000毫秒的超时时间   连接http-outgoing-5 [有效] 2019-09-26T07:20:50.228104650Z:   [INFO]位于   org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:773)   〜[elasticsearch-rest-client-7.3.2.jar!/:7.3.2]   2019-09-26T07:20:50.228108350Z:[INFO]在   org.elasticsearch.client.RestClient.performRequest(RestClient.java:218)   〜[elasticsearch-rest-client-7.3.2.jar!/:7.3.2]   2019-09-26T07:20:50.228111750Z:[INFO]在   org.elasticsearch.client.RestClient.performRequest(RestClient.java:205)   〜[elasticsearch-rest-client-7.3.2.jar!/:7.3.2]   2019-09-26T07:20:50.228115350Z:[INFO]在   org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1454)   〜[elasticsearch-rest-high-level-client-7.3.2.jar!/:7.3.2]   2019-09-26T07:20:50.228118850Z:[INFO]在   org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1439)   〜[elasticsearch-rest-high-level-client-7.3.2.jar!/:7.3.2]   2019-09-26T07:20:50.228122150Z:[INFO]在   org.elasticsearch.client.IndicesClient.exists(IndicesClient.java:784)   〜[elasticsearch-rest-high-level-client-7.3.2.jar!/:7.3.2]

失败后,重试尝试成功完成。

我尝试在LowLevelRestClient上添加嗅探器-但没有效果。

可能有什么麻烦? 谢谢!

0 个答案:

没有答案