I am trying to write a query that will match a document with a nested object that is an array of objects. Example :
{"ListName" : "List 1", "Fruits": [ { "name" : "Apple"}, {"name": "Orange"}, {"name" : "banana"} ] }
I would like to write a query were I get the document above based on the names inside the Fruits array, e.g. Apple and Orange.
What I currently have matches names with both Apple and Orange in the same name field rather than each object.
{
"query": {
"nested": {
"path": "Fruits",
"query": {
"bool": {
"must": [
{
"term": {
"Fruits.name": "Apple"
}
},
{
"match": {
"Fruits.name": "Orange"
}
}
]
}
}
}
}
}