Wagtail and Elasticsearch , Lookup "icontains"" not recognised

18 Views Asked by At

I'm trying to run a search with Wagtail (5.2) and Elastic (7)

When I make a search for Users wagtail_admin/users/?q=ffff I got such error

FilterFieldError
Cannot filter search results with field "email". Please add index.FilterField('email') to User.search_fields

Then I add extra field to search fields in the code

class User:

   search_fields = [
        index.SearchField("name", partial_match=True),
        index.FilterField("email", partial_match=True),
    ]

But just got another error

FilterError /wagtail_admin/users/
Could not apply filter on search results: "email__icontains = ffff". Lookup "icontains"" not recognised.

How it can be fixed?

1

There are 1 best solutions below

1
Ersain On

According to documentation of wagtail, you need to use SearchField for full-text search, try replacing the index.FilterField with index.SearchField:

class User:

   search_fields = [
        index.SearchField("name", partial_match=True),
        index.SearchField("email", partial_match=True),
    ]