Skip to content

Sorting an empty result should not fail. #1908

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
KOSSOKO opened this issue Aug 24, 2021 · 4 comments
Closed

Sorting an empty result should not fail. #1908

KOSSOKO opened this issue Aug 24, 2021 · 4 comments
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@KOSSOKO
Copy link

KOSSOKO commented Aug 24, 2021

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
        }
    }
}

elastic/elasticsearch#1558

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 ?

@sothawo
Copy link
Collaborator

sothawo commented Aug 26, 2021

Currently it is not possible to pass this to Spring Data Elasticsearch. I created #1911 to address this.

@sothawo sothawo added the status: waiting-for-feedback We need additional information before we can continue label Aug 26, 2021
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Sep 2, 2021
@KOSSOKO
Copy link
Author

KOSSOKO commented Sep 2, 2021

@spring-projects-issues wich requested information do you need ?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Sep 2, 2021
@sothawo
Copy link
Collaborator

sothawo commented Sep 3, 2021

I just don't want to close an issue without giving the chance of further feedback, so I set the waiting-for-feedback which will close the issue if no further feedback comes from the OP. So I'll close this one now ;-)

@sothawo sothawo closed this as completed Sep 3, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants