【发布时间】:2019-09-07 09:42:49
【问题描述】:
这个问题已经让我发疯了好几天没有解决方案。
我从我的 django 模型创建一个文档,如下所示。
从 django_elasticsearch_dsl 导入字段
@registry.register_document class QuestionDocument(Document):
complete = fields.CompletionField(attr='title')
class Index:
name = 'questions'
class Django:
model = QuestionModel
fields = ['text', 'title']
现在我想执行这样的完成查询:
matched_questions = list(QuestionDocument.search().suggest("suggestions", word, completion={'field': 'complete'}).execute())
但我不断收到以下错误:
elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'Field [complete] is not a completion suggest field')
我认为问题在于该字段的映射未正确创建,但我不知道如何修复它。任何人都可以帮助解决这个问题,这真的让我发疯了。
更新:
我意识到在我的映射中,完整是作为文本字段创建的,我不知道为什么会发生这种情况或如何解决这个问题。这是我的映射:
{
"questions" : {
"mappings" : {
"doc" : {
"properties" : {
"complete" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"text" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
【问题讨论】:
标签: django elasticsearch elasticsearch-dsl