class SearchSuggest(View):
def get(self, request):
key_words = request.GET.get('s','')
current_type = request.GET.get('s_type', '')
if current_type == "article":
re_datas = []
if key_words:
s = ArticleType.search()
s = s.suggest('my_suggest', key_words, completion={
"field":"suggest",
"fuzzy":{
"fuzziness":2
},
"size": 10
})
suggestions = s.execute_suggest()
for match in suggestions.my_suggest[0].options:
source = match._source
re_datas.append(source["title"])
return HttpResponse(json.dumps(re_datas), content_type="application/json")
这个地方代码跟您的一样,界面搜索pythno没东西,在Kibana中搜索倒是有结果
带你彻底掌握Scrapy,用Django+Elasticsearch搭建搜索引擎
了解课程