Description
I have this method
ebookReviewRepository.findByEbookIdOrderByCommentDateDesc(ebookId, PageRequest.of(page, size));
I noticed that when the index is empty, I get the error Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
. This error is due to the fact that elastic search tries to sort and empty result.
They added "ignore_unmapped": true
to ignore it:
{
"from": 0,
"size": "15",
"sort": {
"title": {
"order": "asc",
"ignore_unmapped": true
}
}
}
But it how could i use the ignore_unmapped option in Spring Data elastic search ? There are no traces in the documentation.
I added a check in my services workaround, but for large data, making count each time is not a solution.
// We have to check first if we have data, in order to avoid issues about sorting when empty
if(this.ebookReviewRepository.count() != 0) {
Page<EbookReview> ebookReviewPage = ebookReviewRepository.findByEbookIdOrderByCommentDateDesc(ebookId, PageRequest.of(page, size));
// We add app user name to the review
for(EbookReview review : ebookReviewPage) {
EbookReviewDto ebookReviewDto = createCompleteEbookReviewDto(review, appUserId);
if(ebookReviewDto.getAppUserId() != null) {
rewiewsDtoResult.add(ebookReviewDto);
}
}
isHasNext = ebookReviewPage.hasNext();
}
How could I handle it correctly ? Thanks ?