Docs Menu

How to Run Partial Match Atlas Search Queries

On this page

  • Create the Atlas Search Index
  • Run a Case-Sensitive Partial Match Query

This tutorial describes how to create an index on the sample_mflix.movies collection and run partial string queries against the plot field. To return matches for partial string queries, you can use one of the following operators:

  • The autocomplete operator, which allows you to search the specified fields for a word or phrase that contains the sequence of characters that you specify with your query.
  • The phrase operator, which allows you to search the specified fields for documents that contain the terms in your query string at the distance you specify between the terms.
  • The regex operator, which allows you to search the specified fields for strings using regular expression.
  • The wildcard operator, which allows you to search the specified fields using special characters in your query to match any character.

This tutorial takes you through the following steps:

  1. Set up an Atlas Search index on the plot field in the sample_mflix.movies collection.
  2. Run Atlas Search query for a partial string against the plot field in the sample_mflix.movies collection using autocomplete, phrase, regex, and wildcard operators.

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

In this section, you will create an Atlas Search index on the plot field in the sample_mflix.movies collection for running partial match queries against those fields.

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.

    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

You can use the Visual Editor or the JSON Editor in the Atlas user interface to create the index.

  1. Click Next.
  2. Click Refine Your Index.
  3. Click Add Field.
  4. Configure the following fields:

    UI Field Name
    Configuration
    Field Name
    Enter plot.
    Enable Dynamic Mapping
    Toggle to Off.
  5. Specify the data type and the settings for the operator you want to use to run the query.

  6. Click Save Changes.
  7. Click Create Search Index.

    Note

    The You're All Set! modal window appears to let you know your index is building.

  8. Click the Close button.
  1. Replace the default index definition with the following example index definition for the operator you intend to use for running the query and click Next.

  2. Click Create Search Index.
6

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 on this page to set the language of the examples in this section.


You can use the autocomplete, phrase, regex, and wildcard operators to run a case-sensitive partial match query. This tutorial uses these operators to search for movies whose plot contain the specified partial string. The query uses the following pipeline stages:

  • $search stage to search the collection
  • $limit stage to limit the output to 3 results
  • $project stage to exclude all fields except title and plot

In this section, you will connect to your Atlas cluster and run the sample query using the operator against the plot field in the sample_mflix.movies collection.

←  How to Use Facets with Atlas SearchHow to Use Synonyms with Atlas Search →

Select your language

Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.