0

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.

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question