db.companies.aggregate([
{ '$search': { index: 'company_index', compound: { should: [
{ autocomplete: { path: 'companyName', query: 'fresh'
}
},
{ embeddedDocument: { path: 'produces', operator: {
compound: { must: [
{ equals: {"path": "produces.deleted", "value": false}}
]},
compound: { must: [
{ autocomplete: {"path": "produces.name",
"query": 'fresh',
}
}
]
}
}
}
}
]
}
}
},
{ '$match': { status: 'VERIFIED'
}
},
{ '$sort': { companyName: 1
}
},
{ '$skip': 0
},
{ '$limit': 24
},
{ '$project': { companyName: 1, status: 1, score: {$meta: 'searchScore'}
}
}
],
{ collation: { locale: 'en'
}
})
As you can see in the code i am performing an aggregation in my companies collection. What i want to do is get produces with given query to but order is wrong.
for example;
CompanyName: Frida lmt. produces: ‘fresh apple’
CompanyName: Fresh garden, produces ‘orange’
CompanyName: garden Fresh, produces ‘orange twit’
=
Fresh garden
garden Fresh
Frida lmt.
I want to get companyName matches first then people who has produces by that query. Can someone tell me what i am doing wrong?