django-elasticsearch-dsl icon indicating copy to clipboard operation
django-elasticsearch-dsl copied to clipboard

suggest with completion not working

Open Mohammadhp opened this issue 6 years ago • 3 comments

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')

Mohammadhp avatar Sep 04 '19 16:09 Mohammadhp

Check the view and make sure it's actually returning field.

akhan118 avatar Apr 06 '20 14:04 akhan118

@Mohammadhp I have the same issue! How did you solve that?

m-hoseyny avatar Mar 04 '21 15:03 m-hoseyny

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'})

bashar94 avatar May 29 '21 08:05 bashar94