Forked from simonw/elasticsearch_dsl_facet_override.py
Created
June 19, 2018 18:43
-
-
Save gregorynicholas/4124a9a6e2de2dfa0808041d7173b2a1 to your computer and use it in GitHub Desktop.
Over-riding elasticsearch-dsl FacetedSearch to use .filter, not .post_filter for selected facets - see https://twitter.com/simonw/status/797894804700966912
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailSearch(FacetedSearch): | |
doc_types = [Email] | |
# fields that should be searched | |
fields = ['subject', 'body'] | |
facets = { | |
'inbox': TermsFacet(field='inbox'), | |
} | |
def filter(self, search): | |
""" | |
Over-ride default behaviour (which uses post_filter) to use filter instead. | |
""" | |
filters = Q('match_all') | |
for f in itervalues(self._filters): | |
filters &= f | |
return search.filter(filters) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment