django_elasticsearch_dsl'search_phase_execution_exception','字段[名称]不是完成建议字段'

时间:2019-09-04 15:44:05

标签: django elasticsearch elasticsearch-dsl

我正在尝试使用django-elasticsearch-dsl执行“完成”。所以我创建了以下文档:

@registry.register_document
class QuestionDocument(Document):
    name = fields.TextField(
        attr='title',
        fields={
            'suggest': fields.Completion(),
        }
    )

    class Index:
        name = 'questions'

    class Django:
        model = QuestionModel
        fields = ['text', 'title']

并使用elasticsearch执行补全:

matched_questions = list(QuestionDocument.search().suggest("suggestions", word, completion={'field': 'name.suggest'}).execute())

但是发生以下异常,表明name.suggest不存在映射:

elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'no mapping found for field [name.suggest]')

我在这里做错了什么?我的方法正确吗?还是应该以一种完全不同的方式来做到这一点?

0 个答案:

没有答案