I need to query an ElasticSearch index through the Python module and I am pretty unfamiliar with ElasticSearch. Say my index stores pairs of persons and some information about each pair. I wonder how to create an ElasticSearch query which would give me below pair. Basically, I want to get the some info field value from the pair where person1 is named John White and a teacher and person2 is named Sarah Black and a doctor. I want an exact match, not a fuzzy one.
"person1": {
"name": "John White",
"job": "teacher"
}
"person2": {
"name": "Sarah Black",
"job": "doctor"
}
"some info": "blah blah"
I tried below query but it gives me pairs where only 1 of the pairs matches the info I ask for, the other person's name/job could be very different. How to get an exact match where both persons' info matches?
"query": {
"bool" : {
"must": {
"bool" : {
"should": [
{ "match": { "person1.name": "John White" }},
{ "match": { "person1.job": "teacher" }}
],
"should": [
{ "match": { "person2.name": "Sarah Black" }},
{ "match": { "person2.job": "doctor" }}
]
}
}
}
}
.keywordfor name and job. It will return the exact match. I meanperson1.name.keywordlikewise for the others too.