The response structure for suggest query is not defined.
elastic search dsl uses the query interface to make suggest query which makes the query like this.
'''
{'query': {'match_all': {}}, 'suggest': {'suggestions': {'completion': {'field': 'tags'}, 'text': 'pyt'}}}
'''
and in response we should ideally get a suggest array along with the hits.hits values.
But that suggest array is not present in the response. Where as if i make the same query directly to the ES i do get the suggest value in response.
You can access any key that's in the body. In your case you should be able to do:
result = s.execute()
print(result.suggest.suggestions)
Hope this helps.
Hi @HonzaKral i am getting this error
'list' object has no attribute 'suggest'
for some reason the query is getting triggered like a regular search query and not a suggest query. and i am getting the response.hits.hits values.
but no suggest values.
Hi @HonzaKral It worked. Thanks, I was making a mistake while reading it.
Also i think this piece should be added to the original documentation.
What do you think ??
Yes, this should definitely be in the docs. I addes some information in fc7ace118f597158623bd8eb2e46543d4212fb85
Hi @HonzaKral, I know this issue is closed, but it ties in to the issue I have. So I am hoping you could help me.
I am, like @vi3k6i5 trying to achieve autocomplete. But I want it without the query. I only need the suggest functionality like the following:
{
"suggest": {
"autocompleteSuggester": {
"completion": {
"field": "keywords.completion",
"skip_duplicates": "true"
},
"text": "Fey"
}
}
}
But by using Search() it shows up as:
{
"query": {
"match_all": {}
},
"suggest": {
"autocompleteSuggester": {
"completion": {
"field": "keywords.completion",
"skip_duplicates": "true"
}
}
}
}
How can I remove the match_all query?
Thanks!
I've been trying to do the same things. In the Elasticsearch docs. It looks like they set the size of the match to 0 to return 0 results so:
query = Search()
query = query.extra(size=0)
query = query.suggest('suggestions', search_term, completion={'field':'tags'})
result = query.execute().suggest.suggestions
Most helpful comment
I've been trying to do the same things. In the Elasticsearch docs. It looks like they set the size of the match to 0 to return 0 results so: