I'm trying to delete all the documents from particular index of ES using the following code:
@Autowired
protected ElasticsearchOperations elasticsearchOperations;
@BeforeEach
void beforeEach() {
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
elasticsearchOperations.delete(query, elasticsearchOperations.getIndexCoordinatesFor(ReviewRequestDocument.class));
}
which fails with
java.lang.IllegalArgumentException: id must not be null
I'm puzzled, because similar approach works for counting documents in index:
private long countReviewRequestDocuments() {
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
return elasticsearchOperations.count(query, ReviewRequestDocument.class);
}
So my question is what is the correct way to remove all documents from index?
build.gradleorpom.xmlfile?org.elasticsearch:elasticsearch:7.9.3DeleteByQueryRequestBuilder- that should find you something. You're using the search query while you need the delete by query API called.