On this page
This tutorial describes how to create an index with a facet
definition on string, date, and numeric fields
sample_mflix.movies collection. It shows how to run an Atlas Search
query against those fields for results grouped by values for the string
field and by ranges for the date and numeric fields, including the
count for each of those groups. It takes you through the following
Set up an Atlas Search index with facet definition on the
yearfields in the
Run Atlas Search query against the
releasedfield in the
sample_mflix.moviescollection for results grouped by values for the
genresfield and by ranges for the
To create an Atlas Search index, you must have
Project Data Access Admin or higher access to the project.
To complete these tutorials, in addition to the prerequisites listed in the Atlas Search Tutorials page, you must have an Atlas cluster running one of the following versions:
In this section, you will create an Atlas Search index on the
released fields in the
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 Atlas 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
The following index definition uses
lucene.standard as the
default analyzer for both indexing and querying the fields and
specifies the following for the fields to index:
You can use the Atlas Search Visual Editor or the Atlas Search JSON Editor in the Atlas user interface to create the index.
➤ Use the Select your language drop-down menu to set the language of the examples in this section.
You can use facet in queries that use the
$searchMeta stages. In this
section, connect to your Atlas cluster and the run the sample query
sample_mflix.movies collection using the
$searchMeta stage. MongoDB recommends using the
$searchMeta stage to retrieve metadata results only.
The results show metadata results for two types of facet search. The
genresFacet document shows the number of movies in each genre and
yearFacet document shows a count of the number of movies
within the boundaries:
1910, inclusive lower bound the
1920, exclusive upper bound for the
1910bucket and inclusive lower bound for the
1930, exclusive upper bound for the
1920bucket and inclusive lower bound for the
Take Unit 9 of the Intro To MongoDB Course on MongoDB University. The 1.5
hour unit includes an overview of Atlas Search and lessons on creating Atlas Search
$search queries using compound operators,
and grouping results using
Follow along with this video to learn about how you can create and use a numeric and string facet in your query to group results and retrieve a count of the results in the groups.
Duration: 11 Minutes