Create an Atlas Search Index using the Atlas UI¶
On this page
Serverless instances are in preview and do not support this feature at this time. To learn more, see Serverless Instance Limitations.
This part of the tutorial guides you through creating an Atlas Search index in the Atlas UI for Atlas Search.
You can also create Atlas Search indexes using the Atlas Search API.
This tutorial uses the sample_mflix
database and the movies
collection from the Sample Mflix Dataset.
Procedure¶
Navigate to the Atlas Search page for your project.¶
- 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.
Click Create Index.¶
Select a Configuration Method and click Next.¶
- For a guided experience, select Visual Editor.
- To edit the raw index definition, select JSON Editor.
Enter the Index Name, and set the Database and Collection.¶
In the Index Name field, enter
default
.The index name defaults to default. You can leave the default name in place or choose one of your own.
NoteIf you name your index
default
, you don't need to specify anindex
parameter when using the $search pipeline stage. Otherwise, you must specify the index name using theindex
parameter.Index names must be unique within their namespace.
- In the Database and Collection section, find the
sample_mflix
database, and select themovies
collection.
Specify an index definition.¶
You can create an Atlas Search index that uses dynamic mappings or static mappings. To learn more about dynamic and static mappings, see Static and Dynamic Mappings.
Choose one of the following index definitions to get started with Atlas Search. You can use the Visual Editor or the JSON Editor in the Atlas user interface to create the index.
Dynamic Mappings
The following index definition dynamically indexes the fields of
supported types in the movies
collection.
Visual Editor¶
- Click Next.
- Review the
"default"
index definition for themovies
collection.
JSON Editor¶
- Click Next.
Review the index definition.
Your index definition should look similar to the following:
{ "mappings": { "dynamic": true } } The above index definition dynamically indexes the fields of supported types in each document in the
movies
collection.- Click Next.
Static Mappings
The movies
collection is large, so in order to save space we will
only index the title
, genres
, and plot
fields.
Visual Editor¶
- Click Next.
- Click Refine Your Index.
- Change Dynamic Mapping to Off.
Add the following fields:
Field NameDynamic MappingData Type Configurationgenres
Change Enable Dynamic Mapping to Off.Click Add Data Type, and select String.plot
Change Enable Dynamic Mapping to Off.Click Add Data Type, and select String.title
Change Enable Dynamic Mapping to Off.a. Click Add Data Type, and select String.
- Click Add Data Type, and select Multi.
- Specify
keywordAnalyzer
as the name of the Multi analyzer. - Change Index Analyzer to lucene.keyword.
- Click Save Changes.
JSON Editor¶
Replace the default definition with the following and click Next.
{ "mappings": { "dynamic": false, "fields": { "title": { "type": "string", "analyzer": "lucene.standard", "multi": { "keywordAnalyzer": { "type": "string", "analyzer": "lucene.keyword" } } }, "genres": { "type": "string", "analyzer": "lucene.standard" }, "plot": { "type": "string", "analyzer": "lucene.standard" } } } }
The above index definition specifies:
- The standard analyzer as the default analyzer for all three indexed fields.
- The keyword analyzer as an alternate
analyzer for the
title
field, with the namekeywordAnalyzer
. The keyword analyzer indexes the entire field as a single term, so it only returns results if the search term and the specified field match exactly. For more information aboutmulti
analyzer designations, see Path Construction. - The standard analyzer as the
analyzer by default for queries on the
genres
field, which is an array of strings. For indexing arrays, Atlas Search only requires the data type of the array elements. You don't have to specify that the data is contained in an array in the index definition.
Click Create Search Index.¶
Close the You're All Set! Modal Window.¶
A modal window appears to let you know your index is building. Click the Close button.
Wait for the index to finish building.¶
The index should take about one minute to build. While it is
building, the Status column reads Build in
Progress
. When it is finished building, the
Status column reads Active
.
Next Steps¶
Now that you have created the index, proceed to Run Atlas Search Queries.