How to order search while using nested compounds?

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?

Hi @Atakan_Yildirim,

What i want to do is get produces with given query to but order is wrong.

Every document returned by an Atlas Search query is assigned a score based on relevance, and the documents included in a result set are returned in order from highest score to lowest.

I want to get companyName matches first then people who has produces by that query. Can someone tell me what i am doing wrong?

You can possibly consider modifying the score accordingly. My guess is that in this case, you’d want to increase the score from the companyName search. The autocomplete operator can be specified with a score option.

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.

Is this the current output or your expected output?

Regards,
Jason