Video Transcript (English)
Hi there! In this video you will learn how to use static mapping for Atlas Search. The default field mapping of an Atlas Search index is dynamic mapping, indexing all of the fields, which makes it simple to get started. However, if we have data with a lot of fields, only some of which an end-user of an application might actually care about, we can show relevant results by statically mapping certain fields.
This type of search indexing is called static indexing because the fields that are being queried against are always the same - they are static. Static indexing on specific fields makes the search quick and efficient by minimizing the number of fields to be indexed.
Let’s jump right into our Atlas Search index.
First, we navigate to the Search tab here, and create a search index by clicking here. We will use the visual editor for a guided experience, and ensure that we are creating a search index for the birds collection. Then, we’ll click “next” and “refine your index”.
Let’s imagine we’re creating a bird guidebook application. In this case, the most important fields that contain information that our user might search by are “common_name”, “scientific_name”, “habitat”, and “diet”.
Dynamic mapping indexes all of the fields present in a collection. In order to save time and processing power, we will toggle off dynamic mapping and only index the fields that we anticipate will contain the search terms that our end user might query, by clicking “Add Field” and selecting “common_name” from the Field Name dropdown menu.To set the datatype for the “common_name” field to “string”, we click on the “Add Data Type” button, and make sure the data type is set to string in this dropdown menu.. Off-screen, I’ll add field mappings for “scientific_name”, “habitat”, and “diet” with the string datatype. Don’t forget to click the “save changes” button when you’re done.
Now that we are done creating the field mappings in the search index, we can click on the “Create Search Index” button
That’s it! We’ve created a search index with static field mappings. Sometimes it can take a while to be generated, but we will be notified when it is done.
And now we can query the search index as if it were a search bar in our bird field guide. We can query for “bluebird” here and see the record where “bluebird” matches “common_name” come up first in our search results.
But what if we search for something that we know is in the data, but in a field that we did not index? For example, here I’ll search for a wingspan value. As you can see, there are no results because the wingspan was not indexed.
In this lesson, we discussed creating search indexes with static field mappings, and now we can start to really make our search work in a magical way for our user!
