django-elasticsearch-dsl
django-elasticsearch-dsl copied to clipboard
suggest with completion not working
I create a Document as below :
@registry.register_document
class QuestionDocument(Document):
name = fields.CompletionField(
attr='title'
)
class Index:
name = 'questions'
class Django:
model = QuestionModel
fields = ['text', 'title']
And then try to perform a suggest query with completion as following:
matched_questions = list(QuestionDocument.search().suggest("suggestions", word, completion={'field': 'name'}).execute())
But i get error regarding that name is not a completion suggest field.
elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'Field [name] is not a completion suggest field')
Check the view and make sure it's actually returning field.
@Mohammadhp I have the same issue! How did you solve that?
Change your document field like this
title = fields.TextField(
attr='title',
fields={
'suggest': fields.CompletionField(),
}
)
Then execute
QuestionDocument.search().suggest("suggestions", word, completion={'field': 'title.suggest'})