I have the following data in elastic search:
[
{
"firstName": "John",
"lastName": "Doe",
"id": 10
},
{
"firstName": "Mary",
"lastName": "Jane",
"id": 10
},
{
"firstName": "John",
"lastName": "Lennon",
"id": 12
}
]
I want to write an elastic search query that can match either on firstName or lastName (should) and then filter those results with the id.
the current query that i have written is as follows:
{
"query": {
"bool": {
"filter": [{
"term": {
"id": 10
}
}],
"should": [{
"match": {
"firstName": "john"
}
}, {
"match": {
"lastName": "john"
}
}]
}
}
}
it is my understanding that when i execute the above query, i should only get the record whose firstName is "John" and id is 10. But in actuality, i get multiple records.
What am i doing wrong here? Any help would be appreciated!