Friday 20 August 2021

django-elasticsearch-dsl: how to search across multiple documents?

I have several ElasticSearch documents in Django describing each a different type of object: 'MovieDoc,' 'CartoonDoc,' etc. For now on, I can search across every such document individually:

document = MovieDoc
results = document.search().query('some phrase')

But what if I want to search across all documents at once and get the results altogether sorted by relevance (i.e. not searching every individual document and merging thereafter)?

I have tried something like this based on the documentation of elasticsearch-dsl, but this did not yield any results:

from elasticsearch_dsl import Search    
results = Search(index=['movie_docs', 'cartoon_docs']).query('some phrase')


from django-elasticsearch-dsl: how to search across multiple documents?

No comments:

Post a Comment