Hi @Clima_Champions and welcome to the community forum!!
Based on the above, I tried to create some sample data as:
Atlas atlas-99o4e9-shard-0 [primary] test> db.arrayTest.find()
[
{
_id: ObjectId('66587570ac48209c08560f1f'),
Type: 'Water Management',
ProjectName: 'Clean Water Initiative',
ProjectSummary: 'This project focuses on providing clean and safe drinking water to rural areas.'
},
{
_id: ObjectId('66587570ac48209c08560f20'),
Type: 'Waste Disposal',
ProjectName: 'Waste Management Solutions',
ProjectSummary: 'A comprehensive approach to managing and disposing of waste sustainably.'
},
{
_id: ObjectId('66587570ac48209c08560f21'),
Type: 'Infrastructure',
ProjectName: 'Urban Wastewater Treatment',
ProjectSummary: 'Developing advanced wastewater treatment facilities in urban regions.'
},
{
_id: ObjectId('66587570ac48209c08560f22'),
Type: 'Environmental',
ProjectName: 'Air Quality Control',
ProjectSummary: 'Monitoring and improving air quality in metropolitan areas.'
},
{
_id: ObjectId('66587570ac48209c08560f23'),
Type: 'Sanitation',
ProjectName: 'Waste Reduction Program',
ProjectSummary: 'Implementing strategies to reduce waste generation in cities.'
},
{
_id: ObjectId('66587570ac48209c08560f24'),
Type: 'Water Supply',
ProjectName: 'Fresh Water Access',
ProjectSummary: 'Ensuring access to fresh water in remote communities.'
}
]
with the index created as:
{
"mappings": {
"dynamic": true,
"fields": {
"ProjectName": {
"type": "string"
},
"ProjectSummary": {
"type": "string"
},
"Type": {
"type": "string"
}
}
}
}
and the query I used looks like the following:
Atlas atlas-99o4e9-shard-0 [primary] test> const variations = ["water", "waste", "wastewater"];
Atlas atlas-99o4e9-shard-0 [primary] test> db.arrayTest.aggregate([ { $search: { index: "default", compound: { should: variations.map((term) => ({ compound: { should: [ { text: { query: term, path: "Type", fuzzy: { maxEdits: 2 }, score: { boost: { value: 10 } } } }, { text: { query: term, path: "ProjectName", fuzzy: { maxEdits: 2 }, score: { boost: { value: 8 } } } }, { text: { query: term, path: "ProjectSummary", fuzzy: { maxEdits: 2 } } }], minimumShouldMatch: 1 } })), minimumShouldMatch: 1 } } }, { $limit: 40 }] ).pretty();
[
{
_id: ObjectId('66587570ac48209c08560f24'),
Type: 'Water Supply',
ProjectName: 'Fresh Water Access',
ProjectSummary: 'Ensuring access to fresh water in remote communities.'
},
{
_id: ObjectId('66587570ac48209c08560f20'),
Type: 'Waste Disposal',
ProjectName: 'Waste Management Solutions',
ProjectSummary: 'A comprehensive approach to managing and disposing of waste sustainably.'
},
{
_id: ObjectId('66587570ac48209c08560f1f'),
Type: 'Water Management',
ProjectName: 'Clean Water Initiative',
ProjectSummary: 'This project focuses on providing clean and safe drinking water to rural areas.'
},
{
_id: ObjectId('66587570ac48209c08560f23'),
Type: 'Sanitation',
ProjectName: 'Waste Reduction Program',
ProjectSummary: 'Implementing strategies to reduce waste generation in cities.'
},
{
_id: ObjectId('66587570ac48209c08560f21'),
Type: 'Infrastructure',
ProjectName: 'Urban Wastewater Treatment',
ProjectSummary: 'Developing advanced wastewater treatment facilities in urban regions.'
}
]
I hope this answers your question. If not please help me with the sample data that you have in your collection and the index definition you are using.
Please do not hesitate to reach out in case of further queries.
Best regards
Aasawari