How can i search in elasticsearch dsl python module on multi fields, example on title and body field and order it by created_at field DESC.
I have this example that search only on title field:
q = request.GET.get('q', None)
s = Search(using=elastic_client, index='post').query('match', title=q)
response = s.execute()
how can i do this?
Found solution:
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()
There is also MultiSearch class now. So you it's possible:
from elasticsearch_dsl import MultiSearch, Search
ms = MultiSearch(index='post')
ms = ms.add(Search().filter('term', tags='title'))
ms = ms.add(Search().filter('term', tags='body'))
responses = ms.execute()
and then you can and group it, and order, and so on. But result is a collection of responses by every filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With