我在远程计算机上运行我的ElasticSearch Server。我正在尝试从本地计算机上为我的pdf文档编制索引。
我正在使用RestHighLevelClient
创建RestClientBuilder
实例,并且还将超时设置为setMaxRetryTimeoutMillis(60000)
。
经过处理后,少数文档出现An existing connection was forcibly closed by the remote host
异常。
请在为RestHighLevelClient
作为单例创建实例的地方找到我的代码。
private static RestClientBuilder builder = RestClient.builder(new HttpHost("Server_machine.com", 9200, "http"),
new HttpHost("Server_machine.com", 9201, "http"))
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setConnectTimeout(5000)
.setSocketTimeout(600000);
}
})
.setMaxRetryTimeoutMillis(60000);
private static RestHighLevelClient instance4 = new RestHighLevelClient(builder);
public static RestHighLevelClient getInstance3() {
return instance4;
}
请找到错误的完整堆栈跟踪。
Exception in thread "main" java.io.IOException: An existing connection was forci
bly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(Unknown Source)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.read(Unknown Source)
at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
at org.apache.http.impl.nio.reactor.SessionInputBufferImpl.fill(SessionI
nputBufferImpl.java:204)
at org.apache.http.impl.nio.codecs.AbstractMessageParser.fillBuffer(Abst
ractMessageParser.java:136)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(De
faultNHttpClientConnection.java:241)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(Inter
nalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(Inter
nalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(Abstra
ctIODispatch.java:114)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor
.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(Abstr
actIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(Abst
ractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIO
Reactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.
java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.
run(AbstractMultiworkerIOReactor.java:588)
at java.lang.Thread.run(Unknown Source)
我们可以将setConnectTimeout(5000)
设置为几个小时,因为我的代码将运行很长时间。