|
10 | 10 | from django.shortcuts import get_object_or_404 |
11 | 11 | from drf_yasg import openapi |
12 | 12 | from drf_yasg.utils import swagger_auto_schema |
| 13 | +from elasticsearch import RequestError |
13 | 14 | from elasticsearch_dsl import Q |
14 | 15 | from pydash import get |
15 | 16 | from rest_framework import response, generics, status |
|
22 | 23 | from core.common.constants import SEARCH_PARAM, LIST_DEFAULT_LIMIT, CSV_DEFAULT_LIMIT, \ |
23 | 24 | LIMIT_PARAM, NOT_FOUND, MUST_SPECIFY_EXTRA_PARAM_IN_BODY, INCLUDE_RETIRED_PARAM, VERBOSE_PARAM, HEAD, LATEST, \ |
24 | 25 | BRIEF_PARAM |
| 26 | +from core.common.exceptions import Http400 |
25 | 27 | from core.common.mixins import PathWalkerMixin |
26 | 28 | from core.common.serializers import RootSerializer |
27 | 29 | from core.common.utils import compact_dict_by_values, to_snake_case, to_camel_case, parse_updated_since_param, \ |
@@ -535,8 +537,13 @@ def get_search_results_qs(self): |
535 | 537 | page = int(self.request.GET.get('page', '1')) |
536 | 538 | start = (page - 1) * self.limit |
537 | 539 | end = start + self.limit |
538 | | - |
539 | | - return search_results[start:end].to_queryset() |
| 540 | + try: |
| 541 | + return search_results[start:end].to_queryset() |
| 542 | + except RequestError as ex: |
| 543 | + if get(ex, 'info.error.caused_by.reason', '').startswith('Result window is too large'): |
| 544 | + raise Http400(detail='Only 10000 results are available. Please apply additional filters' |
| 545 | + ' or fine tune your query to get more accurate results.') |
| 546 | + raise ex |
540 | 547 |
|
541 | 548 | def is_head(self): |
542 | 549 | return self.request.method.lower() == 'head' |
|
0 commit comments