Skip to content

Provide a generic mechanism for building filter when missing is selected #563

@arthurzenika

Description

@arthurzenika

When building a facet with FacetedSearch one can specify to the TermsFacet the label for when the searched attribute is missing :

class MyFacetedSearch(FacetedSearch):
    facets = {
        'myattribute': TermsFacet(field='myattribute', missing='no myattribute')
}

The search generated by that item is the standard one and so will erroneously look for the "no myattribute" value in "myattribute".

Our hack so far to get this to work is the following :

class MyFacetedSearch(FacetedSearch):
    facets = {
        'myattribute': MyAttributeTermsFacet(field='myattribute', missing='no myattribute')
}
class MyAttributeTermsFacet(TermsFacet):
    def add_filter(self, filter_values):
        if 'no myattribute' in filter_values:
            return Q('missing', field='myattribute')
        return super(MyAttributeTermsFacet, self).add_filter(filter_values)

There must be a better way. Is there better way's place in the elasticsearch-dsl library ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions