How to sort Atlas search results?

My use case is a bit strange. I’d like to use Atlas search (full text search) because I want the ability to filter on arbitrary columns (the collection has a dynamic Atlas search that covers all columns). I also want to have the search result sorted by a given column.

Here are my findings:

  1. It seems the “$search” operator in the aggregation pipeline doesn’t support sorting. If I use “$sort” outside of “$search”, sorting basically happens in memory after search is done. With a large collection (eg: hundreds of millions), this would be very slow well.

  2. The closest I can find is the “$near” operator (with a heavy weight), which can be used to mimic sorting because results will be returned by how close they are to the column (to which $near is applied). One limitation of $near is that it only supports “number” and “date” columns.

Elastic Search has no trouble sorting results based on any column of any type as far as I can tell.

Is my understanding correct? Thanks for your expert input!

1 Like

Would love to get an answer on how to best $sort after $search. I have a $search that uses synonyms which I believe isn’t support by fuzzy matching.

Hi there! We have an early version of a solution to address this. Feel free to vote on this feedback item to be updated on availability. Thanks!

1 Like

Thanks for the response but I am not seeing anywhere that actually addresses a solution, just that there might be an implementation at some point.

Any update about this? we are in the same spot, search go fast but we can’t order, drops the performance a lot.

Hi, the suggestion is to use “stored source” if you plan to use $sort. This should help your performance incrementally. We are working on a more performant solution. If you could fill this form out, that would be incredibly helpful in assuring we are meeting your needs.

1 Like

The form ask for permission, seems that I dont have it

Hi @icp the form should be fixed now. (

1 Like