mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 16:53:10 +00:00
Fix __isnull=True lookup for Elasticsearch 5
This commit is contained in:
parent
46746d86e4
commit
f2ad4cea3c
2 changed files with 23 additions and 7 deletions
|
|
@ -16,6 +16,27 @@ class Elasticsearch5Index(Elasticsearch2Index):
|
|||
class Elasticsearch5SearchQuery(Elasticsearch2SearchQuery):
|
||||
mapping_class = Elasticsearch5Mapping
|
||||
|
||||
def _process_lookup(self, field, lookup, value):
|
||||
column_name = self.mapping.get_field_column_name(field)
|
||||
|
||||
if lookup == 'isnull':
|
||||
query = {
|
||||
'exists': {
|
||||
'field': column_name,
|
||||
}
|
||||
}
|
||||
|
||||
if value:
|
||||
query = {
|
||||
'bool': {
|
||||
'mustNot': query
|
||||
}
|
||||
}
|
||||
|
||||
return query
|
||||
|
||||
return super(Elasticsearch5SearchQuery, self)._process_lookup(field, lookup, value)
|
||||
|
||||
def _connect_filters(self, filters, connector, negated):
|
||||
if filters:
|
||||
if len(filters) == 1:
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@ from .test_backends import BackendTests
|
|||
class TestElasticsearch5SearchBackend(BackendTests, ElasticsearchCommonSearchBackendTests, TestCase):
|
||||
backend_path = 'wagtail.search.backends.elasticsearch5'
|
||||
|
||||
# Broken
|
||||
@unittest.expectedFailure
|
||||
def test_filter_isnull_true(self):
|
||||
super(TestElasticsearch5SearchBackend, self).test_filter_isnull_true()
|
||||
|
||||
# Broken
|
||||
@unittest.expectedFailure
|
||||
def test_delete(self):
|
||||
|
|
@ -190,7 +185,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|||
# Check it
|
||||
expected_result = {'bool': {'filter': [
|
||||
{'match': {'content_type': 'searchtests.Book'}},
|
||||
{'missing': {'field': 'title_filter'}}
|
||||
{'bool': {'mustNot': {'exists': {'field': 'title_filter'}}}}
|
||||
], 'must': {'multi_match': {'query': 'Hello', 'fields': ['_all', '_partials']}}}}
|
||||
self.assertDictEqual(query.get_query(), expected_result)
|
||||
|
||||
|
|
@ -201,7 +196,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|||
# Check it
|
||||
expected_result = {'bool': {'filter': [
|
||||
{'match': {'content_type': 'searchtests.Book'}},
|
||||
{'missing': {'field': 'title_filter'}}
|
||||
{'bool': {'mustNot': {'exists': {'field': 'title_filter'}}}}
|
||||
], 'must': {'multi_match': {'query': 'Hello', 'fields': ['_all', '_partials']}}}}
|
||||
self.assertDictEqual(query.get_query(), expected_result)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue