-
Notifications
You must be signed in to change notification settings - Fork 0
Atlas Search
Zhamri Che Ani edited this page Feb 1, 2025
·
3 revisions
{
"name": "sample_supplies-sales-dynamic",
"searchAnalyzer": "lucene.standard",
"analyzer": "lucene.standard",
"collectionName": "sales",
"database": "sample_supplies",
"mappings": {
"dynamic": true
}
}The /app/search_index.json file contains the Atlas search index definition. Here is an overview of the fields defined:
- The
namefield specifies the name of the index as it will appear in MongoDB Atlas. - The
searchAnalyzerspecifies the analyzer to apply to query text before searching with it. In this example, we use the default lucene.standard analyzer. - The
analyzerdefines how Atlas search will turn a string field's contents into searchable terms. It defines the tokenizer used to extract tokens from the > text and filters to use. In this example, we use the default lucene.standard analyzer. - The
collectionNameand database define the collection and database on which to create the index. - The
mappingsobject is used to define the mapping to use, dynamic or static. In this example, we are using dynamic which means that we want Atlas > Search to automatically index all supported field types.
To create the Atlas Search index:
atlas clusters search indexes create --clusterName myAtlasClusterEDU -f /app/search_index.json
To verify that the index creation has started, please run the following command in the terminal:
atlas clusters search indexes list --clusterName myAtlasClusterEDU --db sample_supplies --collection sales
Run the following findOne() command to obtain sample document.
db.sales.findOne()
var pipeline = [
{
$search: {
index: "sample_supplies-sales-dynamic",
text: {
query: "notepad",
path: { "wildcard": "*" }
} } },
{
$set: {
score: {
$meta: "searchScore" }
}
}
]
db.sales.aggregate(pipeline)