On this page
The procedures in this tutorial might not be sufficient to optimize search query performance for all use cases. To provide feedback on your use case, use the MongoDB Feedback Engine.
This tutorial describes the various ways to sort your Atlas Search results based on your performance needs. You can sort for speed, precision, or for both.
First, this tutorial creates an index with static mappings for the
fields in the
sample_mflix.movies collection on
mongot. It also
uses the storedSource option for
title field only. Storing fields on
mongot allows you
to perform interim operations such as sort on documents with a minimum
number of fields and avoid full document lookup in the interim
stages. Then, the tutorial shows how to sort the query results using
the field stored on
Before you begin, ensure that your Atlas cluster meets the requirements described in the Prerequisites.
In this section, you will create an Atlas Search index on the
year fields in the
collection and configure the
option for the
title field to store that field on
If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it is not already displayed, select your desired project from the Projects menu in the navigation bar.
Click your cluster's name.
Click the Search tab.
In the Index Name field, enter
If you name your index
default, you don't need to specify an
indexparameter when using the $search pipeline stage. Otherwise, you must specify the index name using the
In the Database and Collection section, find the
sample_mflixdatabase, and select the
Use the Visual Editor or the JSON Editor in the Atlas user interface to create an index definition that:
yearfields as date and number field types respectively.
Analyzes the title field using the
lucene.keywordanalyzer for the
➤ Use the Select your language drop-down menu to set the language of the example in this section.
You can sort your search results in multiple ways. The queries in this section demonstrate how to sort your search results using the following:
returnStoredSource option for retrieving the field stored on
score options for altering the scores of matching results
This method is highly resource intensive and not recommended in production.