Docs Menu

Docs HomeStart with Guides

Build an Index with Static Field Mappings

In this guide, you will learn how to index only specified fields in documents by creating an index with static field mappings. This allows you to perform more targeted searches.

Time required: 15 minutes

1
2
sample-data-cluster
3

Click the Collections tab.

sample-data-tab
4
1

In the right-hand pane, click sample_supplies, then click the sales collection.

2

Click Search Indexes in the upper right of the collection preview pane.

3

Click Create Search Index.

4

Click the Visual Editor configuration method, then click Next.

5

Review the Database and Collection list to ensure that sample_supplies.sales is selected, then click Next.

5
1

On the Search Tester page, type London into the search bar, then click Search.

2

Your results should include the fields listed in the following sample documents.

SCORE: 0.8888952136039734
salesDate: 2017-12-03T18:39:48.253+00:00
items: Array
storeLocation: "London"
SCORE: 0.8888952136039734
salesDate: 2015-05-15T13:43:24.561+00:00
items: Array
storeLocation: "London"
SCORE: 0.8888952136039734
salesDate: 2016-02-06T09:35:02.820+00:00
items: Array
storeLocation: "London"

Each record also includes a relevance score. You can expand Array and Object fields to view their contents by clicking on them.

3

Type online into the search bar, then click Search.

Even though some records include the string online in the purchaseMethod field, no records appear. The index only has a mapping for the storeLocation field, meaning Atlas Search will only return records with matching values in the storeLocation field.

4

Click Edit Query Syntax. The modal window displays the query sent through the Atlas Search API.

If you successfully completed the procedure in this guide, you have created an Atlas Search index with a static field mapping, and used it to perform a targeted relevance-based search. In the next guide, you will learn how to perform compound searches against specific fields using the aggregation pipeline.

What's Next
Querying with the Compound Operator
15 mins

Retrieve documents in MongoDB with a query on multiple fields.

Start Guide
Chapter 3
Atlas Search
  • Build a Dynamic Index
  • Build an Index with Static Field Mappings
  • Querying with the Compound Operator
  • Querying with Facets
Share Feedback
© 2023 MongoDB, Inc.

About

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