Now, RestHighLevelClient is deprecated.
So i want rewrite code with ElasticSearch Java Api Client in my spring project.
Most of the functions are being modified properly, but I have not found an appropriate way to modify this function.
Below is my existing code.
// import org.elasticsearch.index.reindex.DeleteByQueryRequest;
private String deleteLarge(String indexName, Long categoryNumber, Optional<Long> age) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
.filter(QueryBuilders.matchQuery("category", categoryNumber));
age.ifPresent(a -> boolQueryBuilder
.filter(QueryBuilders.matchQuery("age", a)));
DeleteByQueryRequest request = new DeleteByQueryRequest(indexName)
.setQuery(boolQueryBuilder)
.setSlices(10);
try {
TaskSubmissionResponse taskSubmissionResponse = restHighLevelClient.submitDeleteByQueryTask(request, RequestOptions.DEFAULT);
logger.info("DeleteByQueryTask task id: {}", taskSubmissionResponse.getTask());
return taskSubmissionResponse.getTask();
} catch (Exception e) {
logger.error(e.getMessage());
}
return null;
}
The purpose of this code is to delete a very large volume of documents (ranging from tens of thousands to millions). Since it was difficult to estimate the execution time, I submitted a task to be performed internally by ES.
However, it seems that the ElasticSearch Java API Client does not have such a feature. In the official documentation, there is a Class like ElasticsearchTasksClient, which provides the ability to get info or cancel task, but not to submit new tasks.
Here are my questions:
- Does ES no longer support tasks? Is it gradually being deprecated?
- If not, is there another way to submit new tasks?
- If it is indeed unavailable, is there another method to achieve similar functionality? Would using
deleteByQueryinElasticsearchAsyncClientbe equivalent to submitting a task?