我将elasticsearch添加到我的项目中,几乎所有的东西都能工作,但是现在我不能添加 community
对象通过管理面板。当我尝试这样做时,我得到了与elasticsearch相关的奇怪错误。我试着用谷歌搜索,但没有找到任何有用的信息。也许你们中的一些人也面临同样的问题,知道如何解决它。错误
文档.py
community_index = Index('coms')
community_index.settings(
number_of_shards=1,
number_of_replicas=0
)
html_strip = analyzer(
'html_strip',
tokenizer="standard",
filter=["standard", "lowercase", "stop", "snowball"],
char_filter=["html_strip"]
)
@community_index.doc_type
class CommunityDocument(Document):
id = fields.IntegerField(attr='id')
title = fields.TextField(
analyzer=html_strip,
fields={
'raw': fields.TextField(analyzer='keyword'),
}
)
class Django:
model = communities_models.Community
序列化程序.py
class CommunityDocumentSerializer(DocumentSerializer):
class Meta:
document = communities_documents.CommunityDocument
fields = (
'id',
'title',
)
视图.py
class CommunityViewSet(DocumentViewSet):
document = communities_documents.CommunityDocument
serializer_class = communities_serializers.CommunityDocumentSerializer
lookup_field = 'id'
filter_backends = [
FilteringFilterBackend,
OrderingFilterBackend,
DefaultOrderingFilterBackend,
SearchFilterBackend,
]
search_fields = (
'title',
)
filter_fields = {
'id': {
'field': 'id',
'lookups': [
LOOKUP_FILTER_RANGE,
LOOKUP_QUERY_IN,
LOOKUP_QUERY_GT,
LOOKUP_QUERY_GTE,
LOOKUP_QUERY_LT,
LOOKUP_QUERY_LTE,
],
},
'title': 'title.raw',
}
ordering_fields = {
'id': 'id',
'title': 'title.raw',
}
ordering = ('id')
下面是我使用的应用程序
'elasticsearch_dsl','django_elasticsearch_dsl','django_elasticsearch_dsl_drf',
elasticsearch配置
ELASTICSEARCH_DSL = {
'default': {
'hosts': 'localhost:9200'
},
}
暂无答案!
目前还没有任何答案,快来回答吧!