Docs Menu

Create an Atlas Search Index using the Atlas UI

On this page

  • Procedure
  • Next Steps
Important
Serverless Instances are in Preview

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.

Tip

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.

1
  1. If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
  2. If it is not already displayed, select your desired project from the Projects menu in the navigation bar.
  3. Click your cluster's name.
  4. Click the Search tab.
2
3
  • For a guided experience, select Visual Editor.
  • To edit the raw index definition, select JSON Editor.
4
  1. 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.

    Note

    If you name your index default, you don't need to specify an index parameter when using the $search pipeline stage. Otherwise, you must specify the index name using the index parameter.

    Index names must be unique within their namespace.

  2. In the Database and Collection section, find the sample_mflix database, and select the movies collection.
5

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.

  1. Click Next.
  2. Review the "default" index definition for the movies collection.
  1. Click Next.
  2. 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.

  3. 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.

  1. Click Next.
  2. Click Refine Your Index.
  3. Change Dynamic Mapping to Off.
  4. Add the following fields:

    Field Name
    Dynamic Mapping
    Data Type Configuration
    genres
    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.

    1. Click Add Data Type, and select Multi.
    2. Specify keywordAnalyzer as the name of the Multi analyzer.
    3. Change Index Analyzer to lucene.keyword.
    4. Click Save Changes.

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 name keywordAnalyzer. 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 about multi 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.
6
7

A modal window appears to let you know your index is building. Click the Close button.

8

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.

Now that you have created the index, proceed to Run Atlas Search Queries.

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.