Docs Menu

Docs HomeLaunch & Manage MongoDBMongoDB Atlas

How to Use Synonyms with Atlas Search

On this page

  • Required Access
  • Load the Sample Synonyms Source Collection
  • Create the Atlas Search Index With Synonym Mapping Definition
  • Search the Collection

This tutorial describes how to add a collection that configures words as synonyms, create an index that defines synonym mappings on the sample_mflix.movies collection, and run Atlas Search queries against the title field using words that are configured as synonyms.

The tutorial takes you through the following steps:

  1. Load one or more sample synonyms source collections in the sample_mflix database.

  2. Create an Atlas Search index with one or more synonym mappings for the sample_mflix.movies collection.

  3. Run Atlas Search queries against the title field in the sample_mflix.movies collection for words configured as synonyms in the synonyms source collection.

Before you begin, ensure that your Atlas cluster meets the requirements described in the Prerequisites.

Note

To create multiple synonym mappings and run the advanced sample query in this tutorial, you will need an M10 or higher cluster.

To create an Atlas Search index, you must have Project Data Access Admin or higher access to the project.

Each document in the synonyms source collection describe how one or more words map to one or more synonyms of those words. To learn more about the fields and word mapping types in the synonyms source collection documents, see Format of Synonyms Source Collection Documents.

To begin, you create the synonyms source collection and then add the collection to the database where you intend to use the synonyms source collection. In this section, you create one or two sample synonyms source collections in the sample_mflix database, and then use the synonyms source collections with an index of the movies collection in the same database.

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. If the Database Deployments page is not already displayed, click Database in the sidebar.

2
3

If you are running a free or shared tier cluster, follow the steps in the Transportation Synonyms tab to create the collection for a single synonym mapping definition in your index. If you have a M10 or higher cluster and wish to create multiple synonym mappings in your index, follow the steps in both the tabs to create both the Transportation Synonyms and Attire Synonyms collections.

4

Follow the steps in the tabs to load data into the respective collection.

The synonym mapping in a collection's index specifies the synonyms source collection and the analyzer to use with the collection.

In this section, you create an Atlas Search index that defines one or many synonym mappings for the sample_mflix.movies collection. The mapping definition in the index references the synonyms source collection that you created in the sample_mflix database.

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 Atlas Search tab.

2
3
  • For a guided experience, select the Atlas Search Visual Editor.

  • To edit the raw index definition, select the Atlas Search JSON Editor.

4
  1. In the Index Name field, enter synonyms-tutorial.

    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.

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

5

To run the simple example query only, use the index definition in the Single Synonym Mapping tab below. If you have an M10 or higher cluster and if you loaded both the example synonyms source collections, you can run both the simple and advanced example queries using the index definition that specifies multiple synonym mappings in the Multiple Synonym Mappings tab below.

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.


Use the Select your language drop-down menu to set the language of the examples in this section.


Synonyms can be used only in queries that use the text operator. In this section, you connect to your Atlas cluster and then run the sample queries using the text operator against the title field in the sample_mflix.movies collection. The sample queries use words that are configured as synonyms of different mapping types in the synonyms source collection. The source collection is referenced in the synonyms mapping that the queries use.

←  How to Use Facets with Atlas SearchUpdate $text Queries with Atlas Search for Improved Search Performance →