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')
You can use a wildcard operator (*) as the index to search across all documents.
Implementation details may change over time. See the documentation on Multi-target syntax for information pertaining to your version of Elasticsearch.
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
client = Elasticsearch()
s = Search(using=client, index="*")
response = s.execute()
for hit in response:
print(hit)
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