Repository: wagtail/wagtail

Issue:
Eleasticsearch7 empty admin search gives 500
### Issue Summary

When in the admin panel you click on the search icon you get a 500 error. Or when you clear the search input on the global search page you wel see 500 response in network tab.

full stack trace:

```
  File "/home/userapp/env/lib/python3.9/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/userapp/env/lib/python3.9/site-packages/wagtail/admin/views/generic/permissions.py", line 32, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/home/userapp/env/lib/python3.9/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/userapp/env/lib/python3.9/site-packages/wagtail/admin/views/pages/search.py", line 131, in get
    return super().get(request)
  File "/home/userapp/env/lib/python3.9/site-packages/django/views/generic/list.py", line 154, in get
    self.object_list = self.get_queryset()
  File "/home/userapp/env/lib/python3.9/site-packages/wagtail/admin/views/pages/search.py", line 155, in get_queryset
    for content_type_id, count in self.all_pages.facet(
  File "/home/userapp/env/lib/python3.9/site-packages/wagtail/search/backends/elasticsearch5.py", line 686, in facet
    body = self._get_es_body()
  File "/home/userapp/env/lib/python3.9/site-packages/wagtail/search/backends/elasticsearch5.py", line 715, in _get_es_body
    body = {"query": self.query_compiler.get_query()}
  File "/home/userapp/env/lib/python3.9/site-packages/wagtail/search/backends/elasticsearch5.py", line 582, in get_query
    inner_query = self.get_inner_query()
  File "/home/userapp/env/lib/python3.9/site-packages/wagtail/search/backends/elasticsearch6.py", line 243, in get_inner_query
    return self._compile_plaintext_query(self.query, fields)
  File "/home/userapp/env/lib/python3.9/site-packages/wagtail/search/backends/elasticsearch6.py", line 142, in _compile_plaintext_query
    match_query = {"query": query.query_string}
AttributeError: 'MatchAll' object has no attribute 'query_string'
```

### Steps to Reproduce

1. Have project with elasticsearch7 backend configured
2. Login to admin
3. Click on the search icon

### Technical details

-   Python version: 3.9.18
-   Django version: 4.2.9
-   Wagtail version: 5.2.2

### Possible fix

The fix i tried locally that seems to work is change this line: https://github.com/wagtail/wagtail/blob/stable/5.2.x/wagtail/search/backends/elasticsearch6.py#L239 to:

```python
if len(fields) == 0 or not isinstance(self.query, PlainText):
```



Discussion:

Resolving patch:
diff --git a/wagtail/search/backends/elasticsearch5.py b/wagtail/search/backends/elasticsearch5.py
--- a/wagtail/search/backends/elasticsearch5.py
+++ b/wagtail/search/backends/elasticsearch5.py
@@ -653,8 +653,15 @@ def get_inner_query(self):
         if len(fields) == 0:
             # No fields. Return a query that'll match nothing
             return {"bool": {"mustNot": {"match_all": {}}}}
-
-        return self._compile_plaintext_query(self.query, fields)
+        elif isinstance(self.query, PlainText):
+            return self._compile_plaintext_query(self.query, fields)
+        elif isinstance(self.query, MatchAll):
+            return {"match_all": {}}
+        else:
+            raise NotImplementedError(
+                "`%s` is not supported for autocomplete queries."
+                % self.query.__class__.__name__
+            )
 
 
 class Elasticsearch5AutocompleteQueryCompiler(


Test patch:
diff --git a/wagtail/search/tests/test_elasticsearch5_backend.py b/wagtail/search/tests/test_elasticsearch5_backend.py
--- a/wagtail/search/tests/test_elasticsearch5_backend.py
+++ b/wagtail/search/tests/test_elasticsearch5_backend.py
@@ -70,6 +70,31 @@ def test_simple_autocomplete(self):
         }
         self.assertDictEqual(query_compiler.get_query(), expected_result)
 
+    def test_match_all_autocomplete(self):
+        # Create a query
+        query = self.autocomplete_query_compiler_class(
+            models.Book.objects.all(), MATCH_ALL
+        )
+
+        # Check it
+        expected_result = {
+            "bool": {
+                "filter": {"match": {"content_type": "searchtests.Book"}},
+                "must": {"match_all": {}},
+            }
+        }
+        self.assertDictEqual(query.get_query(), expected_result)
+
+    def test_non_supported_queries_autocomplete(self):
+        # Create a query
+        query = self.autocomplete_query_compiler_class(
+            models.Book.objects.all(), Fuzzy("Hello")
+        )
+
+        # Check it
+        with self.assertRaises(NotImplementedError):
+            query.get_query()
+
     def test_match_all(self):
         # Create a query
         query_compiler = self.query_compiler_class(models.Book.objects.all(), MATCH_ALL)