Repository: saleor/saleor

Issue:
elasticsearch 5 - TransportError(400, 'parsing_exception', 'no [query] registered for [missing]')
I try to run saleor with elasticsearch 5 and see django error:
`        TransportError(400, 'parsing_exception', 'no [query] registered for [missing]')`

I have:
1)
changed backend
    from:
`            'BACKEND': 'saleor.search.backends.elasticsearch2',`
    to:
`            'BACKEND': 'saleor.search.backends.elasticsearch5',`

2)
uninstalled python package (pip):
`            elasticsearch==2.4.1`
and installed:
`            elasticsearch==5.4.0 (elasticsearch>=5.0.0,<6.0.0)`

After change
from:
```
        'missing': {
            'field': column_name,
        }
```
to:
```
        "bool": {
            "must_not": {
                "exists": {
                    "field": "user"
                }
            }
        }
```
in _saleor/search/backends/elasticsearch.py_
search works properly


Could you please perform some changes in _elasticsearch5.py_ in order for it to work from the box.
Thank you.
            


Discussion:
@tulsluper Is this a deployment over Heroku? My testing stage on Docker is working fine with search, but I got the same issue when deploying over Heroku.

I'll try this fix later and confirm.
@israelzuniga there was local installation of elasticsearch from repositories.
OS - Ubuntu 16.04
Repositories - https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html
tested with Elasticsearch 5.0.0 and 5.5.0 - "TransportError(400, 'parsing_exception'" issue
I also experienced this.
My fix was to update `elasticsearch.py` to:

```
        # Get pks from results
        pks = [hit['_source']['pk'][0] for hit in hits['hits']['hits']]
        scores = {str(hit['_source']['pk'][0]): hit['_score']
                  for hit in hits['hits']['hits']}
```
and `elasticsearch5.py` changed:
```
class Elasticsearch5SearchResults(Elasticsearch2SearchResults):
    fields_param_name = '_source'
```
in addition to the changes @tulsluper mentioned.
Running local es5 instance on OS X 10.10
I can confirm that the changes from @yeahdef and @tulsluper worked for me as well.
I've done the above steps and then rerun indexing as well and now the search works. However, it doesn't product any results. 
Any thoughts on what can be the reason? I am hosting app on heroku.

**UPD:**  After debugging, fixed it with replacing 
`pks = [hit['_source']['pk'][0] for hit in hits['hits']['hits']]`

to

`pks = [hit['_source']['pk'] for hit in hits['hits']['hits']]`

Resolving patch:
diff --git a/saleor/search/backends/elasticsearch.py b/saleor/search/backends/elasticsearch.py
--- a/saleor/search/backends/elasticsearch.py
+++ b/saleor/search/backends/elasticsearch.py
@@ -447,8 +447,8 @@ def _do_search(self):
         hits = self.backend.es.search(**params)
 
         # Get pks from results
-        pks = [hit['fields']['pk'][0] for hit in hits['hits']['hits']]
-        scores = {str(hit['fields']['pk'][0]): hit['_score']
+        pks = [hit['_source']['pk'] for hit in hits['hits']['hits']]
+        scores = {str(hit['_source']['pk'][0]): hit['_score']
                   for hit in hits['hits']['hits']}
 
         # Initialise results dictionary
diff --git a/saleor/search/backends/elasticsearch5.py b/saleor/search/backends/elasticsearch5.py
--- a/saleor/search/backends/elasticsearch5.py
+++ b/saleor/search/backends/elasticsearch5.py
@@ -71,7 +71,7 @@ def get_query(self):
 
 
 class Elasticsearch5SearchResults(Elasticsearch2SearchResults):
-    fields_param_name = 'stored_fields'
+    fields_param_name = '_source'
 
 
 class Elasticsearch5SearchBackend(Elasticsearch2SearchBackend):
diff --git a/saleor/settings.py b/saleor/settings.py
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -351,7 +351,7 @@ def get_host():
 if ES_URL:
     SEARCH_BACKENDS = {
         'default': {
-            'BACKEND': 'saleor.search.backends.elasticsearch2',
+            'BACKEND': 'saleor.search.backends.elasticsearch5',
             'URLS': [ES_URL],
             'INDEX': os.environ.get('ELASTICSEARCH_INDEX_NAME', 'storefront'),
             'TIMEOUT': 5,


Test patch: