Im attempting to Search a collection by a populated subdocument, however Im unable to achieve this.
My model (purchases) is the following:
{
amount:{ type:Number} ,
_entityBuyer: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Entity',
},
}
Example of model:
{
amount:150,
_entityBuyer: {
_id:'1234',
name:'lee',
handle:'lee'
}
}
So I’m wanting to lookup all purchases by the _entityBuyer.name via the following:
{
index: 'search-index-name',
compound: {
should: [
{
embeddedDocument: {
path: '_entityBuyer',
operator: {
compound: {
should: [
{
autocomplete: {
query: 'lee',
path: '_entityBuyer.name',
},
},
],
},
},
},
},
],
},
My Search Index is the following:
{
"mappings": {
"fields": {
"_entityBuyer": {
"dynamic": false,
"fields": {
"name": {
"type": "autocomplete"
}
},
"type": "embeddedDocuments"
}
}
}
}
Currently running the above returns an empty result - however I have correctly seeded my database with _entityBuyer.name with the value of ‘lee’
Any help or guidance would be greatly appreciated