Consider using the compound operator. I assume you’ll just need to use text and equals (or range if you want 5 years and greater of experience).
Example documents and $search query using equals:
test> db.collection.find({},{_id:0})
[
{ primary_skills: [ 'java' ], yoe: 3 },
{ primary_skills: [ 'jAVA' ], yoe: 4 },
{ primary_skills: [ 'JaVa' ], yoe: 5 }, /// <--- 5 years of experience
{ primary_skills: [ 'javA' ], yoe: 5 } /// <--- 5 years of experience
]
Query and output:
test> db.collection.aggregate([
{
'$search': {
compound: {
must: [
{ text: { query: 'java', path: 'primary_skills' } },
{ equals: { path: 'yoe', value: 5 } }
]
}
}
}
])
[
{
_id: ObjectId('657f7b0fb4f063d7c3533e83'),
primary_skills: [ 'JaVa' ],
yoe: 5
},
{
_id: ObjectId('657f7b16b4f063d7c3533e84'),
primary_skills: [ 'javA' ],
yoe: 5
}
]
Regards,
Jason