Ajay Venkatesh
Ajay Venkatesh

Reputation: 27

DeleteByQueryRequest socket timeout exception - java high level rest client api

I'm a beginner to elasticsearch and I want to delete a huge amount of document which matches to the particular query. I'm using DeleteByQueryRequest for this purpose. I tried the code below.

String fileName="output2.log";
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(new HttpHost("localhost", 9200, "http")));
DeleteByQueryRequest deleteRequest = new DeleteByQueryRequest("_all");
deleteRequest.setQuery(QueryBuilders.termQuery("fileName.keyword",fileName));
deleteRequest.setTimeout(TimeValue.timeValueMinutes(10));
//deleteRequest.setRefresh(true);
BulkByScrollResponse bulkResponse = client.deleteByQuery(deleteRequest, RequestOptions.DEFAULT);
client.close();
System.out.println(bulkResponse.isTimedOut());
System.out.print("Deletion done");

When I run this code, the respective documents gets deleted but this code throws the below exception.

java.net.SocketTimeoutException: 30,000 milliseconds timeout on connection http-outgoing-0 [ACTIVE]

What can be done to get rid of this exception? Thanks in advance.

Upvotes: 0

Views: 952

Answers (1)

Ajay Venkatesh
Ajay Venkatesh

Reputation: 27

After some research i found that the default socket timeout for RestHighLevelClient is 30000ms. I used the below code to extend the socket timeout duration.

RestHighLevelClient client = new RestHighLevelClient((RestClient.builder(new 
      HttpHost(localhost,9200,"http"))).setRequestConfigCallback(requestConfigBuilder ->                         
     requestConfigBuilder                        
    .setConnectTimeout(10000)
    .setSocketTimeout(60000)
    .setConnectionRequestTimeout(0)
));

Now you can able to increase the timelimit in setSocketTimout() method.

Upvotes: 0

Related Questions