wagtail and elasticsearch不支持__contains?

问题描述 投票:2回答:1

我希望能够在我的自定义页面模型之一中进行搜索。搜索应排除列表中所有预定义的page.id,并且还应排除page.url_path包含特定值的位置。

例如:

from django.db.models import Q

# The view
def search(request, search_query):
    ...
    CustomPageModel.objects.live().exclude(
        Q(id__in=list_page_ids) | 
        Q(url_path__icontains='notsearchable')
    ).search(search_query))

这在我使用时有效:

WAGTAILSEARCH_BACKENDS = {
    'default': {
        'BACKEND': 'wagtail.contrib.postgres_search.backend',
    }
}

但是当我使用时不起作用:

WAGTAILSEARCH_BACKENDS = {
    'default': {
        'BACKEND': 'wagtail.search.backends.elasticsearch6',
        ...
    }
}

我从Elasticsearch作为后端得到的错误:

FilterError at /search/query/
Could not apply filter on search results: "url_path__icontains = notsearchable". Lookup "icontains"" not recognised.

Elasticsearch不支持icontains

那么如何排除和搜索相同的模型?

ps。 CustomModel用于不同的url_paths中,因此不应对模型本身进行任何更改。

django elasticsearch wagtail wagtail-search
1个回答
0
投票

__overlap完全相同。请告诉我有人知道了吗?

© www.soinside.com 2019 - 2024. All rights reserved.