ElasticSearch - RestHighLevelClient java.io.IOExce

2019-07-19 03:28发布

问题:

Am fetch 100K plus documents from an Index using single query. For that am using ScrollSearch API. After that am iterating each and every doucments one by one and adding one more field into that and creating a new index for that.

Am using RestHighLevelClient for the connectivity between Java Code and ElasticSearch. I have set Timeout options for 25 hours (setMaxRetryTimeoutMillis(90000000)).

But, still am getting the below exception after 30 minutes

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)

My ElasticSearch server is running on remote machine. Once i got this exception, my remote machine ES server also get shutdown automatically.

Please find the code below, where i creating instance for 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;
    }