A micro library for performing multi-search/multi-percolate queries on Elasticsearch using elasticseach-py
pip install gambit
Let queries be expressed in the form of python dictionaries.
query1 = {...}
query2 = {...}
query3 = {...}
document1 = {...}
To perform a multisearch use Msearch
class
from elasticsearch import Elasticsearch
from gambit import Msearch
search = Msearch(Elasticsearch(), index='some-index', doc-type='some-doc-type')
Use add
method of Msearch
class to build a query.
search.add(query1)
search.add(query2)
search.add(query3)
Use execute
method of Msearch
class to fire the aggregated query.
list_of_results = search.execute()
Use percolate_and_get
function to percolate and fetch all matching documents.
matching_docs = precolate_and_get(Elasticsearch(), document1,
index='some-index', doc-type='some-doc-type')
Look at full documentation here