I'm trying to match on more than one field when querying an ES server via the Python API. But can't figure out the syntax within Python:
I've tried;
res = es.search(index="pyats", doc_type="router_show", body={"query": {"match": {"name": "mark"} AND {"age": "21"}}}, size=1000)
and
res = es.search(index="pyats", doc_type="router_show", body={"query": {"match_all": {"name": "mark"} AND {"age": "21"}}}, size=1000)
and
res = es.search(index="pyats", doc_type="router_show", body={"query": {"match": {"name": "mark"}}, {"match": {"age": "21"}}}, size=1000)
Any advice would be greatly appreciated. None, seem to be working.
Please make sure that age field is of the type integer or string. The keyword which will solve your problem is must.
{
"query": {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : { "age" : 21 } },
{ "term" : { "name" : "mark" } }
]
}
}
}
}
}
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