I’ve successfully created a search index for two of my documents. I’ve also created mongo search aggregation methods for the corresponding index’s. My profiler however is complaining that none of my index’s are being used (keys examined is 0) and I’m not sure what the issue is. Initially the index’s i created were static as i thought that the way i setup the index was the issue but even when i switched to a dynamic index I’m getting no keys examined.
The following is a small code snippet for the aggregation pipeline (which I’m assuming is causing the issue)
const query = [
{
$search: {
index: 'directSearchIndex',
compound: {
should: [
{
text: {
query: searchTerm,
path: 'email',
},
},
{
text: {
query: searchTerm,
path: 'phone',
},
},
{
text: {
query: cleanWebsiteUrl,
path: 'website',
},
},
],
},
},
},
{
$limit: 5,
},
{
$project: {
_id: 1,
website: 1,
email: 1,
},
},
];
return await User.aggregate(query).exec();
The cleanWebsiteUrl param is just the search term with the protocol stripped off. The index im using now is a dynamic index (copied and pasted from the docs):
{
"mappings": {
"dynamic": true
}
}