3

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.

1 Answer 1

2

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" } } 
                    ]
                }
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.