I couldn't get the CompoundSearchFilterBackend class in the django-elasticsearch-dsl-drf library to work properly

27 Views Asked by At

I'm using the CompoundSearchFilterBackend class in the django-elasticsearch-dsl-drf library to perform queries. However, I'm receiving all queries.

Django==4.2.9
django-elasticsearch-dsl==7.3
django-elasticsearch-dsl-drf==0.22.5

Below is an example of cached data from Elasticsearch along with other relevant classes.

    {
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "betik_app_municy_citizen_municipal_council",
        "_id": "1",
        "_score": 1,
        "_source": {
          "party_name": "party",
          "title": "title",
          "full_name": "erhan koçlar",
          "email": "[email protected]",
          "id": 1,
          "substitute": false
        }
      }
    ]
  }
}

documents.py

@registry.register_document
class MunicipalCouncilDocument(Document):
    class Index:
        name = f"{APP_LABEL}_municipal_council"
        settings = {
            'number_of_shards': 1,
            'number_of_replicas': 0
        }

    class Django:
        model = MunicipalCouncilModel

        fields = [
            'id',
            'substitute'
        ]

    party_name = fields.TextField()

    title = fields.TextField()

    full_name = fields.TextField()

    email = fields.KeywordField()

    def prepare_full_name(self, instance):
        return f"{instance.person.name} {instance.person.last_name}"

   
    def prepare_email(self, instance):
        return instance.person.email

    
    def prepare_party_name(self, instance):
        return instance.political_party.name

    def prepare_title(self, instance):
        return instance.title.exp

    def get_queryset(self):

        # visible
        return super().get_queryset() \
            .filter(
                visible=True
        ) \
            .order_by('order_no')

views.py

class PaginateDocumentView(DocumentViewSet):
    """
        Paginate municipal councils (cache)

        Paginate cached municipal councils
    """
    document = MunicipalCouncilDocument
    serializer_class = MunicipalCouncilDocumentSerializer
    pagination_class = StandardPagination
    authentication_classes = []
    filter_backends = [
        CompoundSearchFilterBackend,
     
    ]

    

    search_fields = (
        'full_name',
        'email'
    )

When I make a query like

HTTP://..../?search=wwwwwwww

, data is returned. In this query, no data should be returned at all.

0

There are 0 best solutions below