Navigation

Create an Atlas Search Index

This part of the tutorial guides you through creating an Atlas Search index in the Atlas UI for Atlas Search.

1
2
  • For a guided experience, select Visual Editor.
  • To edit the raw index definition, select JSON Editor.
3
  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.
4

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

Visual Editor
  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.
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 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.
5
6

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

7

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

On this page

  • Procedure
  • Next Steps