使用单个查询从索引中获取100K
和文档。为此,使用的是ScrollSearch
API。之后,逐个迭代每个文档,并向其中添加一个字段,并为此创建一个新索引。
我使用RestHighLevelClient
来实现Java代码和ElasticSearch之间的连接。我为Timeout
小时设置了25
个选项(setMaxRetryTimeoutMillis(90000000))。
但是,30分钟后仍会出现以下异常
Exception in thread "main" java.io.IOException: An existing connection was forcibly 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(SessionInputBufferImpl.java:204)
at org.apache.http.impl.nio.codecs.AbstractMessageParser.fillBuffer(AbstractMessageParser.java:136)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:241)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.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)
我的ElasticSearch服务器正在远程计算机上运行。一旦遇到此异常,我的远程计算机ES服务器也会自动关闭。
请在下面找到我为RestHighLevelClient
创建实例的代码。
private static RestClientBuilder builder = RestClient.builder(new HttpHost("My_Server.com", 9200, "http"),
new HttpHost("My_Server.com", 9201, "http"))
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setConnectTimeout(90000000)//25hours
.setSocketTimeout(90000000);
}
})
.setMaxRetryTimeoutMillis(90000000);
private static RestHighLevelClient instance4 = new RestHighLevelClient(builder);
public static RestHighLevelClient getInstance3() {
return instance4;
}