We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
update_index not working with Elasticsearch 5.4
When running `python manage.py update_index` the following errors occurs:
```
elasticsearch.exceptions.RequestError: TransportError(400, 'No handler found for uri [//storefront__userprofile_user] and method [DELETE]')
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `saleor/search/backends/dashboard.py`
Content:
```
1 from collections import defaultdict
2 
3 from . import get_search_backend
4 from .base import BaseSearchQuery
5 from ..index import get_indexed_models
6 
7 CONTENT_TYPES_MAP = {
8     model.indexed_get_content_type(): model
9     for model in get_indexed_models()}
10 
11 DEFAULT_BACKEND = get_search_backend('default')
12 DEFAULT_BACKEND_CLASS = DEFAULT_BACKEND.__class__
13 DEFAULT_BACKEND_RESULTS_CLASS = DEFAULT_BACKEND.results_class
14 
15 
16 class DashboardSearchQuery(BaseSearchQuery):
17     """
18     Query that will search in multiple indexes
19     """
20 
21     def __init__(self, query_string,
22                  fields=None, operator=None, order_by_relevance=True,
23                  queryset_map=None):
24         if queryset_map:
25             queryset_map = {model.indexed_get_content_type(): queryset
26                             for model, queryset in queryset_map.items()}
27         else:
28             queryset_map = {content_type: model.objects.all()
29                             for content_type, model in CONTENT_TYPES_MAP.items()}
30         self.queryset_map = queryset_map
31         super(DashboardSearchQuery, self).__init__(
32             query_string=query_string, queryset=None, fields=fields,
33             operator=operator, order_by_relevance=order_by_relevance)
34 
35     def get_inner_query(self):
36         if self.query_string is not None:
37             fields = self.fields or ['_all', '_partials']
38 
39             if len(fields) == 1:
40                 if self.operator == 'or':
41                     query = {
42                         'match': {
43                             fields[0]: self.query_string,
44                         }
45                     }
46                 else:
47                     query = {
48                         'match': {
49                             fields[0]: {
50                                 'query': self.query_string,
51                                 'operator': self.operator,
52                             }
53                         }
54                     }
55             else:
56                 query = {
57                     'multi_match': {
58                         'query': self.query_string,
59                         'fields': fields,
60                     }
61                 }
62 
63                 if self.operator != 'or':
64                     query['multi_match']['operator'] = self.operator
65         else:
66             query = {
67                 'match_all': {}
68             }
69 
70         return query
71 
72     def get_query(self):
73         return self.get_inner_query()
74 
75 
76 class DashboardSearchResults(DEFAULT_BACKEND_RESULTS_CLASS):
77 
78     def _do_search(self):
79         # Params for elasticsearch query
80         params = dict(
81             body=self._get_es_body(),
82             _source=False,
83             from_=self.start,
84             index='{}*'.format(self.backend.get_index().name)
85         )
86         params[self.fields_param_name] = 'pk'
87 
88         # Add size if set
89         if self.stop is not None:
90             params['size'] = self.stop - self.start
91         # Send to Elasticsearch
92         hits = self.backend.es.search(**params)
93         search_hits = defaultdict(list)
94         scores = {}
95         for hit in hits['hits']['hits']:
96             hit_type = hit['_type']
97             hit_pk = hit['fields']['pk'][0]
98             search_hits[hit_type].append(hit_pk)
99             scores[hit['_id']] = hit['_score']
100 
101         # Group results by content type
102         results_by_model = {}
103         for content_type, hit_pks in search_hits.items():
104             queryset = self.query.queryset_map[content_type]
105             results_by_model[content_type] = queryset.filter(pk__in=hit_pks)
106 
107         # Merge results back in one list ordered by search score
108         all_results = []
109         for content_type, hits in results_by_model.items():
110             for hit in hits:
111                 score_key = '%s:%d' % (content_type, hit.pk)
112                 setattr(hit, 'search_score', scores[score_key])
113                 setattr(hit, 'content_type', content_type)
114                 all_results.append(hit)
115         sorted_results = sorted(
116             all_results, key=lambda h: h.search_score, reverse=True)
117         return list(sorted_results)
118 
119     def _get_es_body(self, for_count=False):
120         body = {
121             'query': self.query.get_query()
122         }
123 
124         if not for_count:
125             sort = None
126 
127             if sort is not None:
128                 body['sort'] = sort
129 
130         return body
131 
132     def _do_count(self):
133         # Get count
134         hit_count = self.backend.es.count(
135             body=self._get_es_body(for_count=True),
136             index='{}*'.format(self.backend.get_index().name)
137         )['count']
138         # Add limits
139         hit_count -= self.start
140         if self.stop is not None:
141             hit_count = min(hit_count, self.stop - self.start)
142 
143         return max(hit_count, 0)
144 
145 
146 class DashboardMultiTypeSearchBackend(DEFAULT_BACKEND_CLASS):
147     results_class = DashboardSearchResults
148     query_class = DashboardSearchQuery
149 
150     def search(self, query_string,
151                model_or_queryset=None, fields=None, filters=None,
152                prefetch_related=None, operator=None, order_by_relevance=True,
153                queryset_map=None):
154         """
155         Multi-model search. Parameters that affect model or database
156         structure are skipped and not used in dashboard query implementation.
157         """
158         search_query = self.query_class(
159             query_string=query_string, fields=fields, operator=operator,
160             order_by_relevance=order_by_relevance, queryset_map=queryset_map)
161         return self.results_class(self, search_query)
162 
163 SearchBackend = DashboardMultiTypeSearchBackend
164
```
--- 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/saleor/search/backends/dashboard.py b/saleor/search/backends/dashboard.py
--- a/saleor/search/backends/dashboard.py
+++ b/saleor/search/backends/dashboard.py
@@ -94,7 +94,7 @@
         scores = {}
         for hit in hits['hits']['hits']:
             hit_type = hit['_type']
-            hit_pk = hit['fields']['pk'][0]
+            hit_pk = hit['_source']['pk']
             search_hits[hit_type].append(hit_pk)
             scores[hit['_id']] = hit['_score']

{"golden_diff": "diff --git a/saleor/search/backends/dashboard.py b/saleor/search/backends/dashboard.py\n--- a/saleor/search/backends/dashboard.py\n+++ b/saleor/search/backends/dashboard.py\n@@ -94,7 +94,7 @@\n         scores = {}\n         for hit in hits['hits']['hits']:\n             hit_type = hit['_type']\n-            hit_pk = hit['fields']['pk'][0]\n+            hit_pk = hit['_source']['pk']\n             search_hits[hit_type].append(hit_pk)\n             scores[hit['_id']] = hit['_score']\n", "issue": "update_index not working with Elasticsearch 5.4\nWhen running `python manage.py update_index` the following errors occurs:\r\n```\r\nelasticsearch.exceptions.RequestError: TransportError(400, 'No handler found for uri [//storefront__userprofile_user] and method [DELETE]')\r\n```\n", "before_files": [{"content": "from collections import defaultdict\n\nfrom . import get_search_backend\nfrom .base import BaseSearchQuery\nfrom ..index import get_indexed_models\n\nCONTENT_TYPES_MAP = {\n    model.indexed_get_content_type(): model\n    for model in get_indexed_models()}\n\nDEFAULT_BACKEND = get_search_backend('default')\nDEFAULT_BACKEND_CLASS = DEFAULT_BACKEND.__class__\nDEFAULT_BACKEND_RESULTS_CLASS = DEFAULT_BACKEND.results_class\n\n\nclass DashboardSearchQuery(BaseSearchQuery):\n    \"\"\"\n    Query that will search in multiple indexes\n    \"\"\"\n\n    def __init__(self, query_string,\n                 fields=None, operator=None, order_by_relevance=True,\n                 queryset_map=None):\n        if queryset_map:\n            queryset_map = {model.indexed_get_content_type(): queryset\n                            for model, queryset in queryset_map.items()}\n        else:\n            queryset_map = {content_type: model.objects.all()\n                            for content_type, model in CONTENT_TYPES_MAP.items()}\n        self.queryset_map = queryset_map\n        super(DashboardSearchQuery, self).__init__(\n            query_string=query_string, queryset=None, fields=fields,\n            operator=operator, order_by_relevance=order_by_relevance)\n\n    def get_inner_query(self):\n        if self.query_string is not None:\n            fields = self.fields or ['_all', '_partials']\n\n            if len(fields) == 1:\n                if self.operator == 'or':\n                    query = {\n                        'match': {\n                            fields[0]: self.query_string,\n                        }\n                    }\n                else:\n                    query = {\n                        'match': {\n                            fields[0]: {\n                                'query': self.query_string,\n                                'operator': self.operator,\n                            }\n                        }\n                    }\n            else:\n                query = {\n                    'multi_match': {\n                        'query': self.query_string,\n                        'fields': fields,\n                    }\n                }\n\n                if self.operator != 'or':\n                    query['multi_match']['operator'] = self.operator\n        else:\n            query = {\n                'match_all': {}\n            }\n\n        return query\n\n    def get_query(self):\n        return self.get_inner_query()\n\n\nclass DashboardSearchResults(DEFAULT_BACKEND_RESULTS_CLASS):\n\n    def _do_search(self):\n        # Params for elasticsearch query\n        params = dict(\n            body=self._get_es_body(),\n            _source=False,\n            from_=self.start,\n            index='{}*'.format(self.backend.get_index().name)\n        )\n        params[self.fields_param_name] = 'pk'\n\n        # Add size if set\n        if self.stop is not None:\n            params['size'] = self.stop - self.start\n        # Send to Elasticsearch\n        hits = self.backend.es.search(**params)\n        search_hits = defaultdict(list)\n        scores = {}\n        for hit in hits['hits']['hits']:\n            hit_type = hit['_type']\n            hit_pk = hit['fields']['pk'][0]\n            search_hits[hit_type].append(hit_pk)\n            scores[hit['_id']] = hit['_score']\n\n        # Group results by content type\n        results_by_model = {}\n        for content_type, hit_pks in search_hits.items():\n            queryset = self.query.queryset_map[content_type]\n            results_by_model[content_type] = queryset.filter(pk__in=hit_pks)\n\n        # Merge results back in one list ordered by search score\n        all_results = []\n        for content_type, hits in results_by_model.items():\n            for hit in hits:\n                score_key = '%s:%d' % (content_type, hit.pk)\n                setattr(hit, 'search_score', scores[score_key])\n                setattr(hit, 'content_type', content_type)\n                all_results.append(hit)\n        sorted_results = sorted(\n            all_results, key=lambda h: h.search_score, reverse=True)\n        return list(sorted_results)\n\n    def _get_es_body(self, for_count=False):\n        body = {\n            'query': self.query.get_query()\n        }\n\n        if not for_count:\n            sort = None\n\n            if sort is not None:\n                body['sort'] = sort\n\n        return body\n\n    def _do_count(self):\n        # Get count\n        hit_count = self.backend.es.count(\n            body=self._get_es_body(for_count=True),\n            index='{}*'.format(self.backend.get_index().name)\n        )['count']\n        # Add limits\n        hit_count -= self.start\n        if self.stop is not None:\n            hit_count = min(hit_count, self.stop - self.start)\n\n        return max(hit_count, 0)\n\n\nclass DashboardMultiTypeSearchBackend(DEFAULT_BACKEND_CLASS):\n    results_class = DashboardSearchResults\n    query_class = DashboardSearchQuery\n\n    def search(self, query_string,\n               model_or_queryset=None, fields=None, filters=None,\n               prefetch_related=None, operator=None, order_by_relevance=True,\n               queryset_map=None):\n        \"\"\"\n        Multi-model search. Parameters that affect model or database\n        structure are skipped and not used in dashboard query implementation.\n        \"\"\"\n        search_query = self.query_class(\n            query_string=query_string, fields=fields, operator=operator,\n            order_by_relevance=order_by_relevance, queryset_map=queryset_map)\n        return self.results_class(self, search_query)\n\nSearchBackend = DashboardMultiTypeSearchBackend\n", "path": "saleor/search/backends/dashboard.py"}], "after_files": [{"content": "from collections import defaultdict\n\nfrom . import get_search_backend\nfrom .base import BaseSearchQuery\nfrom ..index import get_indexed_models\n\nCONTENT_TYPES_MAP = {\n    model.indexed_get_content_type(): model\n    for model in get_indexed_models()}\n\nDEFAULT_BACKEND = get_search_backend('default')\nDEFAULT_BACKEND_CLASS = DEFAULT_BACKEND.__class__\nDEFAULT_BACKEND_RESULTS_CLASS = DEFAULT_BACKEND.results_class\n\n\nclass DashboardSearchQuery(BaseSearchQuery):\n    \"\"\"\n    Query that will search in multiple indexes\n    \"\"\"\n\n    def __init__(self, query_string,\n                 fields=None, operator=None, order_by_relevance=True,\n                 queryset_map=None):\n        if queryset_map:\n            queryset_map = {model.indexed_get_content_type(): queryset\n                            for model, queryset in queryset_map.items()}\n        else:\n            queryset_map = {content_type: model.objects.all()\n                            for content_type, model in CONTENT_TYPES_MAP.items()}\n        self.queryset_map = queryset_map\n        super(DashboardSearchQuery, self).__init__(\n            query_string=query_string, queryset=None, fields=fields,\n            operator=operator, order_by_relevance=order_by_relevance)\n\n    def get_inner_query(self):\n        if self.query_string is not None:\n            fields = self.fields or ['_all', '_partials']\n\n            if len(fields) == 1:\n                if self.operator == 'or':\n                    query = {\n                        'match': {\n                            fields[0]: self.query_string,\n                        }\n                    }\n                else:\n                    query = {\n                        'match': {\n                            fields[0]: {\n                                'query': self.query_string,\n                                'operator': self.operator,\n                            }\n                        }\n                    }\n            else:\n                query = {\n                    'multi_match': {\n                        'query': self.query_string,\n                        'fields': fields,\n                    }\n                }\n\n                if self.operator != 'or':\n                    query['multi_match']['operator'] = self.operator\n        else:\n            query = {\n                'match_all': {}\n            }\n\n        return query\n\n    def get_query(self):\n        return self.get_inner_query()\n\n\nclass DashboardSearchResults(DEFAULT_BACKEND_RESULTS_CLASS):\n\n    def _do_search(self):\n        # Params for elasticsearch query\n        params = dict(\n            body=self._get_es_body(),\n            _source=False,\n            from_=self.start,\n            index='{}*'.format(self.backend.get_index().name)\n        )\n        params[self.fields_param_name] = 'pk'\n\n        # Add size if set\n        if self.stop is not None:\n            params['size'] = self.stop - self.start\n        # Send to Elasticsearch\n        hits = self.backend.es.search(**params)\n        search_hits = defaultdict(list)\n        scores = {}\n        for hit in hits['hits']['hits']:\n            hit_type = hit['_type']\n            hit_pk = hit['_source']['pk']\n            search_hits[hit_type].append(hit_pk)\n            scores[hit['_id']] = hit['_score']\n\n        # Group results by content type\n        results_by_model = {}\n        for content_type, hit_pks in search_hits.items():\n            queryset = self.query.queryset_map[content_type]\n            results_by_model[content_type] = queryset.filter(pk__in=hit_pks)\n\n        # Merge results back in one list ordered by search score\n        all_results = []\n        for content_type, hits in results_by_model.items():\n            for hit in hits:\n                score_key = '%s:%d' % (content_type, hit.pk)\n                setattr(hit, 'search_score', scores[score_key])\n                setattr(hit, 'content_type', content_type)\n                all_results.append(hit)\n        sorted_results = sorted(\n            all_results, key=lambda h: h.search_score, reverse=True)\n        return list(sorted_results)\n\n    def _get_es_body(self, for_count=False):\n        body = {\n            'query': self.query.get_query()\n        }\n\n        if not for_count:\n            sort = None\n\n            if sort is not None:\n                body['sort'] = sort\n\n        return body\n\n    def _do_count(self):\n        # Get count\n        hit_count = self.backend.es.count(\n            body=self._get_es_body(for_count=True),\n            index='{}*'.format(self.backend.get_index().name)\n        )['count']\n        # Add limits\n        hit_count -= self.start\n        if self.stop is not None:\n            hit_count = min(hit_count, self.stop - self.start)\n\n        return max(hit_count, 0)\n\n\nclass DashboardMultiTypeSearchBackend(DEFAULT_BACKEND_CLASS):\n    results_class = DashboardSearchResults\n    query_class = DashboardSearchQuery\n\n    def search(self, query_string,\n               model_or_queryset=None, fields=None, filters=None,\n               prefetch_related=None, operator=None, order_by_relevance=True,\n               queryset_map=None):\n        \"\"\"\n        Multi-model search. Parameters that affect model or database\n        structure are skipped and not used in dashboard query implementation.\n        \"\"\"\n        search_query = self.query_class(\n            query_string=query_string, fields=fields, operator=operator,\n            order_by_relevance=order_by_relevance, queryset_map=queryset_map)\n        return self.results_class(self, search_query)\n\nSearchBackend = DashboardMultiTypeSearchBackend\n", "path": "saleor/search/backends/dashboard.py"}]}