我是弹性搜索的初学者,我想删除大量与特定查询匹配的文档。我为此目的使用 DeleteByQueryRequest。我尝试了下面的代码。
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");
当我运行此代码时,相应的文档会被删除,但此代码会引发以下异常。
java.net.SocketTimeoutException: 30,000 milliseconds timeout on connection http-outgoing-0 [ACTIVE]
可以做些什么来摆脱这个异常?提前致谢。