I have an array of objects inside a document in ES
I want to only match documents where 2 fields inside an object (within the array) match.
My problem is this. Say I have 3 documents (outer document removed) where I have an array of objects such as
// Doc 1
"questionAnswers": [
{
"question": "First yes no question",
"answer": "Yes"
},
{
"question": "Second yes no question",
"answer": "No"
}
]
// Doc 2
"questionAnswers": [
{
"question": "First yes no question",
"answer": "No"
},
{
"question": "Second yes no question",
"answer": "No"
}
]
// Doc 3
"questionAnswers": [
{
"question": "First yes no question",
"answer": "No"
},
{
"question": "Second yes no question",
"answer": "Yes"
}
]
And my query is
{
"from": 0,
"size": 25,
"query": {
"bool": {
"filter": [
{
"match": {
"questionAnswers.question.keyword": "First yes no question"
}
},
{
"match": {
"questionAnswers.answer": "Yes"
}
}
]
}
}
}
I'm currently getting matches for documents 1 and 3. Whereas I only want the first document to match where question = First yes no question and answer = Yes
How can this be achieved?