2

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?

2 Answers 2

6

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()
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.