title: Elasticsearch Bulk API
body: <p>I would like to ask about the Elasticsearch Bulk API </p>
  
  <p>This is my code for using Bulk API </p>
  
  <pre><code>public void bulkInsert(String index, ArrayList&lt;String&gt; jsonList) throws IOException {
      BulkRequest request = new BulkRequest(); 
  
      for(String json: jsonList){
          if(json != null&amp;&amp; !json.isEmpty()){
              request.add(new IndexRequest(index)  
                      .source(json, XContentType.JSON));  
          }
      }
  
      BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
      for (BulkItemResponse bulkItemResponse : bulkResponse) { 
          DocWriteResponse itemResponse = bulkItemResponse.getResponse(); 
  
          switch (bulkItemResponse.getOpType()) {
          case INDEX:    
          case CREATE:
              IndexResponse indexResponse = (IndexResponse) itemResponse;
              break;
          case UPDATE:   
              UpdateResponse updateResponse = (UpdateResponse) itemResponse;
              break;
          case DELETE:   
              DeleteResponse deleteResponse = (DeleteResponse) itemResponse;
          }
      }
      if (bulkResponse.hasFailures()) { 
          for (BulkItemResponse bulkItemResponse : bulkResponse) {
              if (bulkItemResponse.isFailed()) { 
                  BulkItemResponse.Failure failure =
                          bulkItemResponse.getFailure(); 
  
                  System.out.println("failed: " + failure.getId());
  
              }
          }
      }
  }
  </code></pre>
  
  <p>I have encountered the timeout exception as my records have got 800k. 
  java.net.SocketTimeoutException: 30,000 milliseconds timeout on connection http-outgoing-16 [ACTIVE]</p>
  
  <p>I tried to break up the jsonList that I passed in, but sometime will have the same error. </p>
  
  <p>I am currently using Elasticsearch 7.6.2 version. </p>
  
  <p>The exception trace</p>
  
  <blockquote>
    <p>java.net.SocketTimeoutException: 30,000 milliseconds timeout on connection http-outgoing-16 [ACTIVE]
            at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:808)
            at org.elasticsearch.client.RestClient.performRequest(RestClient.java:248)
            at org.elasticsearch.client.RestClient.performRequest(RestClient.java:235)
            at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1514)
            at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1484)
            at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1454)
            at org.elasticsearch.client.RestHighLevelClient.bulk(RestHighLevelClient.java:497)
            at com.ESUtil.bulkInsert(ESUtil.java:110)
            at org.download.App1.main(App1.java:167)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
    Caused by: java.net.SocketTimeoutException: 30,000 milliseconds timeout on connection http-outgoing-16 [ACTIVE]
            at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.timeout(HttpAsyncRequestExecutor.java:387)
            at org.apache.http.impl.nio.client.InternalIODispatch.onTimeout(InternalIODispatch.java:92)
            at org.apache.http.impl.nio.client.InternalIODispatch.onTimeout(InternalIODispatch.java:39)
            at org.apache.http.impl.nio.reactor.AbstractIODispatch.timeout(AbstractIODispatch.java:175)
            at org.apache.http.impl.nio.reactor.BaseIOReactor.sessionTimedOut(BaseIOReactor.java:261)
            at org.apache.http.impl.nio.reactor.AbstractIOReactor.timeoutCheck(AbstractIOReactor.java:502)
            at org.apache.http.impl.nio.reactor.BaseIOReactor.validate(BaseIOReactor.java:211)
            at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:280)
            at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
            at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)
            at java.lang.Thread.run(Unknown Source)</p>
  </blockquote>