How can I dynamically create a combined Q query in elasticsearch dsl python? I have gone through docs and this SO post. I constructed a q_query dictionary with all required info.
ipdb> q_queries
{'queries': [{'status': 'PASS'}, {'status': 'FAIL'}, {'status': 'ABSE'}, {'status': 'WITH'}], 'operation': 'or'}
I want to perform the following q_query
qq=Q("match", status='PASS') | Q("match", status="FAIL") | Q("match", status="ABSE") | Q("match", status="WITH")
for a list of dict following works out
ipdb> [Q('match', **z) for z in q_queries['queries']]
[Match(status='PASS'), Match(status='FAIL'), Match(status='ABSE'), Match(status='WITH')]
But How to combine multiple Qs with an or operator or an and operator? Also what is the corresponding elasticsearch raw query
for the above? I tried following since I have to filter based on test_id.
{
"query": {
"bool": {
"must": [
{ "match": { "test_id": "7" }},
{
"range": {
"created": {
"gte": "2016-01-01",
"lte": "2016-01-31"
}
}
}
],
"should": [
{ "match": { "status": "PASS"}},
{ "match": { "status": "FAIL"}}
]
}
}
}
But results are not as expected I same query without should filter
and the results obtained were the same. So should filters were not executed by elasticsearch in my case.
Any help is much appreciated.
TIA