This tutorial describes how to create an index on the
sample_mflix.movies collection and run partial string queries
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:
- Set up an Atlas Search index on the
plotfield in the
- Run Atlas Search query for a partial string against the
plotfield in the
sample_mflix.moviescollection 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
sample_mflix.movies collection for running partial match
queries against those fields.
- 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.
In the Index Name field, enter
If you name your index
default, you don't need to specify an
indexparameter when using the $search pipeline stage. Otherwise, you must specify the index name using the
- In the Database and Collection section, find the
sample_mflixdatabase, and select the
You can use the Visual Editor or the JSON Editor in the Atlas user interface to create the index.
- Click Next.
- Click Refine Your Index.
- Click Add Field.
Configure the following fields:UI Field NameConfigurationField NameEnter
plot.Enable Dynamic MappingToggle to Off.
Specify the data type and the settings for the operator you want to use to run the query.
- Click Save Changes.
Click Create Search Index.Note
The You're All Set! modal window appears to let you know your index is building.
- Click the Close button.
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.
- Click Create Search Index.
➤ 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:
$searchstage to search the collection
$limitstage to limit the output to
$projectstage to exclude all fields except
In this section, you will connect to your Atlas cluster and run the
sample query using the operator against the
plot field in the