2016-03-08 78 views
0

如何在多字段中搜索elasticsearch dsl python模塊,例如titlebody字段,並通過created_at字段的字段DESC進行排序。Python elasticsearch dsl搜索多字段和順序結果

我有這樣的例子,搜索僅在title領域:

q = request.GET.get('q', None) 
s = Search(using=elastic_client, index='post').query('match', title=q) 
response = s.execute() 

我怎樣才能做到這一點?

回答

0

已找到解決方案:

from elasticsearch_dsl.query import MultiMatch 

q = request.GET.get('q', None) 
query = MultiMatch(query=q, fields=['title', 'body'], fuzziness='AUTO') 
s = Search(using=elastic_client, index='post').query(query) 
response = s.execute()