We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Elasticserach returns paginated results when querying/mapping features using RESDK
In resolwe-bio tools/goea.py `org_features = res.feature.filter(source=args.source_db, query=genes)` should return all genes, not just the first 10.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `resolwe/elastic/viewsets.py`
Content:
```
1 """.. Ignore pydocstyle D400.
2 
3 ================
4 Elastic Viewsets
5 ================
6 
7 .. autoclass:: resolwe.elastic.viewsets.ElasticSearchMixin
8     :members:
9 
10 """
11 from __future__ import absolute_import, division, print_function, unicode_literals
12 
13 from elasticsearch_dsl.query import Q
14 
15 from django.conf import settings
16 from django.contrib.auth import get_user_model
17 
18 from rest_framework.response import Response
19 from rest_framework.viewsets import GenericViewSet
20 
21 __all__ = (
22     'ElasticSearchMixin',
23     'PaginationMixin',
24     'ElasticSearchBaseViewSet',
25 )
26 
27 
28 class ElasticSearchMixin(object):
29     """Mixin to use Django REST Framework with ElasticSearch based querysets.
30 
31     This mixin adds following methods:
32       * :func:`~ElasticSearchMixin.order_search`
33       * :func:`~ElasticSearchMixin.filter_search`
34       * :func:`~ElasticSearchMixin.filter_permissions`
35 
36     """
37 
38     filtering_fields = []
39     ordering_fields = []
40     ordering = None
41 
42     def get_query_param(self, key, default=None):
43         """Get query parameter uniformly for GET and POST requests."""
44         value = self.request.query_params.get(key, None)
45         if value is None:
46             value = self.request.data.get(key, None)
47         if value is None:
48             value = default
49         return value
50 
51     def order_search(self, search):
52         """Order given search by the ordering parameter given in request.
53 
54         :param search: ElasticSearch query object
55 
56         """
57         ordering = self.get_query_param('ordering', self.ordering)
58 
59         ordering_field = ordering.lstrip('-')
60         if ordering_field not in self.ordering_fields:
61             raise KeyError('Ordering by `{}` is not supported.'.format(ordering_field))
62 
63         return search.sort(ordering)
64 
65     def filter_search(self, search):
66         """Filter given search by the filter parameter given in request.
67 
68         :param search: ElasticSearch query object
69 
70         """
71         for field in self.filtering_fields:
72             value = self.get_query_param(field, None)
73             if value:
74                 if isinstance(value, list):
75                     filters = [Q('match', **{field: item}) for item in value]
76                     search = search.query('bool', should=filters)
77                 else:
78                     search = search.query('wildcard', **{field: value})
79 
80         return search
81 
82     def filter_permissions(self, search):
83         """Filter given query based on permissions of the user in the request.
84 
85         :param search: ElasticSearch query object
86 
87         """
88         user = self.request.user
89         if user.is_superuser:
90             return search
91         if user.is_anonymous():
92             user_model = get_user_model()
93             user = user_model.objects.get(**{user_model.USERNAME_FIELD: settings.ANONYMOUS_USER_NAME})
94 
95         filters = [Q('match', users_with_permissions=user.pk)]
96         filters.extend([
97             Q('match', groups_with_permissions=group.pk) for group in user.groups.all()
98         ])
99 
100         # `minimum_should_match` is set to 1 by default
101         return search.query('bool', should=filters)
102 
103 
104 class PaginationMixin(object):
105     """Mixin for making paginated response in case pagination parameters are provided."""
106 
107     def paginate_response(self, queryset):
108         """Optionally return paginated response.
109 
110         If pagination parameters are provided in the request, then paginated response
111         is returned, otherwise response is not paginated.
112 
113         """
114         page = self.paginate_queryset(queryset)
115         if page is not None:
116             serializer = self.get_serializer(page, many=True)
117             return self.get_paginated_response(serializer.data)
118 
119         serializer = self.get_serializer(queryset, many=True)
120         return Response(serializer.data)
121 
122 
123 class ElasticSearchBaseViewSet(PaginationMixin, ElasticSearchMixin, GenericViewSet):
124     """Base ViewSet for ElasticSearch based views.
125 
126     This ViewSet creates search based on ``document_class`` parameter, specified
127     in subclass and:
128 
129       * filter it by query parameters
130       * apply ordering
131       * filter permissions
132       * apply pagination
133 
134     .. IMPORTANT::
135 
136         Both ``POST`` and ``GET`` requests are supported.
137     """
138 
139     document_class = None
140 
141     def custom_filter(self, search):
142         """Perform custom search filtering.
143 
144         This method is intended to be overriden in subclasses.
145         """
146         return search
147 
148     def list_with_post(self, request):
149         """Endpoint handler."""
150         search = self.document_class().search()  # pylint: disable=not-callable
151 
152         search = self.custom_filter(search)
153 
154         search = self.filter_search(search)
155         search = self.order_search(search)
156         search = self.filter_permissions(search)
157 
158         return self.paginate_response(search)
159 
160     def list(self, request):
161         """Endpoint handler."""
162         return self.list_with_post(request)
163
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/resolwe/elastic/viewsets.py b/resolwe/elastic/viewsets.py
--- a/resolwe/elastic/viewsets.py
+++ b/resolwe/elastic/viewsets.py
@@ -15,6 +15,7 @@
 from django.conf import settings
 from django.contrib.auth import get_user_model
 
+from rest_framework.exceptions import APIException
 from rest_framework.response import Response
 from rest_framework.viewsets import GenericViewSet
 
@@ -24,6 +25,16 @@
     'ElasticSearchBaseViewSet',
 )
 
+ELASTICSEARCH_SIZE = 10000  # maximum number of results returned by ElasticSearch
+
+
+class TooManyResults(APIException):
+    """Exception when elastic query returns more than ``ELASTICSEARCH_SIZE`` results."""
+
+    status_code = 400
+    default_detail = 'Query returned too many results. Please, add more filters or use pagination.'
+    default_code = 'bad_request'
+
 
 class ElasticSearchMixin(object):
     """Mixin to use Django REST Framework with ElasticSearch based querysets.
@@ -155,6 +166,11 @@
         search = self.order_search(search)
         search = self.filter_permissions(search)
 
+        if search.count() > ELASTICSEARCH_SIZE:
+            raise TooManyResults()
+
+        search = search.extra(size=ELASTICSEARCH_SIZE)
+
         return self.paginate_response(search)
 
     def list(self, request):

{"golden_diff": "diff --git a/resolwe/elastic/viewsets.py b/resolwe/elastic/viewsets.py\n--- a/resolwe/elastic/viewsets.py\n+++ b/resolwe/elastic/viewsets.py\n@@ -15,6 +15,7 @@\n from django.conf import settings\n from django.contrib.auth import get_user_model\n \n+from rest_framework.exceptions import APIException\n from rest_framework.response import Response\n from rest_framework.viewsets import GenericViewSet\n \n@@ -24,6 +25,16 @@\n     'ElasticSearchBaseViewSet',\n )\n \n+ELASTICSEARCH_SIZE = 10000  # maximum number of results returned by ElasticSearch\n+\n+\n+class TooManyResults(APIException):\n+    \"\"\"Exception when elastic query returns more than ``ELASTICSEARCH_SIZE`` results.\"\"\"\n+\n+    status_code = 400\n+    default_detail = 'Query returned too many results. Please, add more filters or use pagination.'\n+    default_code = 'bad_request'\n+\n \n class ElasticSearchMixin(object):\n     \"\"\"Mixin to use Django REST Framework with ElasticSearch based querysets.\n@@ -155,6 +166,11 @@\n         search = self.order_search(search)\n         search = self.filter_permissions(search)\n \n+        if search.count() > ELASTICSEARCH_SIZE:\n+            raise TooManyResults()\n+\n+        search = search.extra(size=ELASTICSEARCH_SIZE)\n+\n         return self.paginate_response(search)\n \n     def list(self, request):\n", "issue": "Elasticserach returns paginated results when querying/mapping features using RESDK\nIn resolwe-bio tools/goea.py `org_features = res.feature.filter(source=args.source_db, query=genes)` should return all genes, not just the first 10.\n", "before_files": [{"content": "\"\"\".. Ignore pydocstyle D400.\n\n================\nElastic Viewsets\n================\n\n.. autoclass:: resolwe.elastic.viewsets.ElasticSearchMixin\n    :members:\n\n\"\"\"\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom elasticsearch_dsl.query import Q\n\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model\n\nfrom rest_framework.response import Response\nfrom rest_framework.viewsets import GenericViewSet\n\n__all__ = (\n    'ElasticSearchMixin',\n    'PaginationMixin',\n    'ElasticSearchBaseViewSet',\n)\n\n\nclass ElasticSearchMixin(object):\n    \"\"\"Mixin to use Django REST Framework with ElasticSearch based querysets.\n\n    This mixin adds following methods:\n      * :func:`~ElasticSearchMixin.order_search`\n      * :func:`~ElasticSearchMixin.filter_search`\n      * :func:`~ElasticSearchMixin.filter_permissions`\n\n    \"\"\"\n\n    filtering_fields = []\n    ordering_fields = []\n    ordering = None\n\n    def get_query_param(self, key, default=None):\n        \"\"\"Get query parameter uniformly for GET and POST requests.\"\"\"\n        value = self.request.query_params.get(key, None)\n        if value is None:\n            value = self.request.data.get(key, None)\n        if value is None:\n            value = default\n        return value\n\n    def order_search(self, search):\n        \"\"\"Order given search by the ordering parameter given in request.\n\n        :param search: ElasticSearch query object\n\n        \"\"\"\n        ordering = self.get_query_param('ordering', self.ordering)\n\n        ordering_field = ordering.lstrip('-')\n        if ordering_field not in self.ordering_fields:\n            raise KeyError('Ordering by `{}` is not supported.'.format(ordering_field))\n\n        return search.sort(ordering)\n\n    def filter_search(self, search):\n        \"\"\"Filter given search by the filter parameter given in request.\n\n        :param search: ElasticSearch query object\n\n        \"\"\"\n        for field in self.filtering_fields:\n            value = self.get_query_param(field, None)\n            if value:\n                if isinstance(value, list):\n                    filters = [Q('match', **{field: item}) for item in value]\n                    search = search.query('bool', should=filters)\n                else:\n                    search = search.query('wildcard', **{field: value})\n\n        return search\n\n    def filter_permissions(self, search):\n        \"\"\"Filter given query based on permissions of the user in the request.\n\n        :param search: ElasticSearch query object\n\n        \"\"\"\n        user = self.request.user\n        if user.is_superuser:\n            return search\n        if user.is_anonymous():\n            user_model = get_user_model()\n            user = user_model.objects.get(**{user_model.USERNAME_FIELD: settings.ANONYMOUS_USER_NAME})\n\n        filters = [Q('match', users_with_permissions=user.pk)]\n        filters.extend([\n            Q('match', groups_with_permissions=group.pk) for group in user.groups.all()\n        ])\n\n        # `minimum_should_match` is set to 1 by default\n        return search.query('bool', should=filters)\n\n\nclass PaginationMixin(object):\n    \"\"\"Mixin for making paginated response in case pagination parameters are provided.\"\"\"\n\n    def paginate_response(self, queryset):\n        \"\"\"Optionally return paginated response.\n\n        If pagination parameters are provided in the request, then paginated response\n        is returned, otherwise response is not paginated.\n\n        \"\"\"\n        page = self.paginate_queryset(queryset)\n        if page is not None:\n            serializer = self.get_serializer(page, many=True)\n            return self.get_paginated_response(serializer.data)\n\n        serializer = self.get_serializer(queryset, many=True)\n        return Response(serializer.data)\n\n\nclass ElasticSearchBaseViewSet(PaginationMixin, ElasticSearchMixin, GenericViewSet):\n    \"\"\"Base ViewSet for ElasticSearch based views.\n\n    This ViewSet creates search based on ``document_class`` parameter, specified\n    in subclass and:\n\n      * filter it by query parameters\n      * apply ordering\n      * filter permissions\n      * apply pagination\n\n    .. IMPORTANT::\n\n        Both ``POST`` and ``GET`` requests are supported.\n    \"\"\"\n\n    document_class = None\n\n    def custom_filter(self, search):\n        \"\"\"Perform custom search filtering.\n\n        This method is intended to be overriden in subclasses.\n        \"\"\"\n        return search\n\n    def list_with_post(self, request):\n        \"\"\"Endpoint handler.\"\"\"\n        search = self.document_class().search()  # pylint: disable=not-callable\n\n        search = self.custom_filter(search)\n\n        search = self.filter_search(search)\n        search = self.order_search(search)\n        search = self.filter_permissions(search)\n\n        return self.paginate_response(search)\n\n    def list(self, request):\n        \"\"\"Endpoint handler.\"\"\"\n        return self.list_with_post(request)\n", "path": "resolwe/elastic/viewsets.py"}], "after_files": [{"content": "\"\"\".. Ignore pydocstyle D400.\n\n================\nElastic Viewsets\n================\n\n.. autoclass:: resolwe.elastic.viewsets.ElasticSearchMixin\n    :members:\n\n\"\"\"\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom elasticsearch_dsl.query import Q\n\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model\n\nfrom rest_framework.exceptions import APIException\nfrom rest_framework.response import Response\nfrom rest_framework.viewsets import GenericViewSet\n\n__all__ = (\n    'ElasticSearchMixin',\n    'PaginationMixin',\n    'ElasticSearchBaseViewSet',\n)\n\nELASTICSEARCH_SIZE = 10000  # maximum number of results returned by ElasticSearch\n\n\nclass TooManyResults(APIException):\n    \"\"\"Exception when elastic query returns more than ``ELASTICSEARCH_SIZE`` results.\"\"\"\n\n    status_code = 400\n    default_detail = 'Query returned too many results. Please, add more filters or use pagination.'\n    default_code = 'bad_request'\n\n\nclass ElasticSearchMixin(object):\n    \"\"\"Mixin to use Django REST Framework with ElasticSearch based querysets.\n\n    This mixin adds following methods:\n      * :func:`~ElasticSearchMixin.order_search`\n      * :func:`~ElasticSearchMixin.filter_search`\n      * :func:`~ElasticSearchMixin.filter_permissions`\n\n    \"\"\"\n\n    filtering_fields = []\n    ordering_fields = []\n    ordering = None\n\n    def get_query_param(self, key, default=None):\n        \"\"\"Get query parameter uniformly for GET and POST requests.\"\"\"\n        value = self.request.query_params.get(key, None)\n        if value is None:\n            value = self.request.data.get(key, None)\n        if value is None:\n            value = default\n        return value\n\n    def order_search(self, search):\n        \"\"\"Order given search by the ordering parameter given in request.\n\n        :param search: ElasticSearch query object\n\n        \"\"\"\n        ordering = self.get_query_param('ordering', self.ordering)\n\n        ordering_field = ordering.lstrip('-')\n        if ordering_field not in self.ordering_fields:\n            raise KeyError('Ordering by `{}` is not supported.'.format(ordering_field))\n\n        return search.sort(ordering)\n\n    def filter_search(self, search):\n        \"\"\"Filter given search by the filter parameter given in request.\n\n        :param search: ElasticSearch query object\n\n        \"\"\"\n        for field in self.filtering_fields:\n            value = self.get_query_param(field, None)\n            if value:\n                if isinstance(value, list):\n                    filters = [Q('match', **{field: item}) for item in value]\n                    search = search.query('bool', should=filters)\n                else:\n                    search = search.query('wildcard', **{field: value})\n\n        return search\n\n    def filter_permissions(self, search):\n        \"\"\"Filter given query based on permissions of the user in the request.\n\n        :param search: ElasticSearch query object\n\n        \"\"\"\n        user = self.request.user\n        if user.is_superuser:\n            return search\n        if user.is_anonymous():\n            user_model = get_user_model()\n            user = user_model.objects.get(**{user_model.USERNAME_FIELD: settings.ANONYMOUS_USER_NAME})\n\n        filters = [Q('match', users_with_permissions=user.pk)]\n        filters.extend([\n            Q('match', groups_with_permissions=group.pk) for group in user.groups.all()\n        ])\n\n        # `minimum_should_match` is set to 1 by default\n        return search.query('bool', should=filters)\n\n\nclass PaginationMixin(object):\n    \"\"\"Mixin for making paginated response in case pagination parameters are provided.\"\"\"\n\n    def paginate_response(self, queryset):\n        \"\"\"Optionally return paginated response.\n\n        If pagination parameters are provided in the request, then paginated response\n        is returned, otherwise response is not paginated.\n\n        \"\"\"\n        page = self.paginate_queryset(queryset)\n        if page is not None:\n            serializer = self.get_serializer(page, many=True)\n            return self.get_paginated_response(serializer.data)\n\n        serializer = self.get_serializer(queryset, many=True)\n        return Response(serializer.data)\n\n\nclass ElasticSearchBaseViewSet(PaginationMixin, ElasticSearchMixin, GenericViewSet):\n    \"\"\"Base ViewSet for ElasticSearch based views.\n\n    This ViewSet creates search based on ``document_class`` parameter, specified\n    in subclass and:\n\n      * filter it by query parameters\n      * apply ordering\n      * filter permissions\n      * apply pagination\n\n    .. IMPORTANT::\n\n        Both ``POST`` and ``GET`` requests are supported.\n    \"\"\"\n\n    document_class = None\n\n    def custom_filter(self, search):\n        \"\"\"Perform custom search filtering.\n\n        This method is intended to be overriden in subclasses.\n        \"\"\"\n        return search\n\n    def list_with_post(self, request):\n        \"\"\"Endpoint handler.\"\"\"\n        search = self.document_class().search()  # pylint: disable=not-callable\n\n        search = self.custom_filter(search)\n\n        search = self.filter_search(search)\n        search = self.order_search(search)\n        search = self.filter_permissions(search)\n\n        if search.count() > ELASTICSEARCH_SIZE:\n            raise TooManyResults()\n\n        search = search.extra(size=ELASTICSEARCH_SIZE)\n\n        return self.paginate_response(search)\n\n    def list(self, request):\n        \"\"\"Endpoint handler.\"\"\"\n        return self.list_with_post(request)\n", "path": "resolwe/elastic/viewsets.py"}]}