gpt4 book ai didi

django - django-elasticsearch-dsl-drf建议网址给出404错误

转载 作者:行者123 更新时间:2023-12-03 02:23:30 25 4
gpt4 key购买 nike

我正在使用django-elasticsearch-dsl-drf并配置了带有建议completedfield的文档。我的观点定论也有一些建议。

文件:

class ProductsDocument(Document):
productName = fields.TextField(
attr='productName',
fields={
'raw': fields.KeywordField(),
'suggest': fields.CompletionField(),
}
)

description = fields.TextField(
analyzer=html_strip,
fields={
'raw': fields.KeywordField(),
'suggest': fields.CompletionField(),
'lower': fields.Text(analyzer=html_strip),
}
)

View 集:
class ProductsView(BaseDocumentViewSet):
document = ProductsDocument
serializer_class = ProductsSerializer
pagination_class = PageNumberPagination
lookup_field = 'id'
filter_backends = [
FilteringFilterBackend,
SuggesterFilterBackend,
IdsFilterBackend,
OrderingFilterBackend,
DefaultOrderingFilterBackend,
CompoundSearchFilterBackend,
NestedFilteringFilterBackend,
CompoundSearchFilterBackend,

]

search_fields = (
'productName',
'price',
'inStock',
'description',
'sellerprof.country.name',
)

suggester_fields = {
'productName_suggest': {
'field': 'productName.suggest',
'suggesters': [
SUGGESTER_COMPLETION,
],
'default_suggester': SUGGESTER_COMPLETION,
},

'description_suggest': {
'field': 'description.suggest',
'suggesters': [
SUGGESTER_COMPLETION,
],
'default_suggester': SUGGESTER_COMPLETION,
},
'productName_suggest': 'productName.suggest',
'description_suggest': 'description.suggest',
}

当我尝试使用建议完成URL时,出现NotFoundError

enter image description here

我不确定我缺少什么。

最佳答案

我有类似的问题。有人为我提供了解决方案,并且有效。因此,如果您遇到相同的问题,请通过以下链接检查我的问题。然后,该解决方案也将为您服务。

Django elasticsearch DSL DRF suggetions issue

您只需要继承DocumentViewSet而不是BaseDocumentViewSet。

关于django - django-elasticsearch-dsl-drf建议网址给出404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61759418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com