Atlas Search queries are run as an aggregation pipeline stage. Atlas搜索查询作为聚合管道阶段运行。If you have an existing Atlas Search Index for data on your Atlas cluster, you can run 如果Atlas集群上已有Atlas搜索索引,则可以运行$search and $searchMeta queries. $search和$searchMeta查询。If you have an existing Atlas Vector search index on your data in Atlas, you can also run 如果您在Atlas中的数据上有一个现有的Atlas Vector搜索索引,您还可以运行$vectorSearch queries.$vectorSearch查询。
Before You Begin开始之前
Create an Atlas Search index or an Atlas Vector Search index.创建Atlas搜索索引或Atlas矢量搜索索引。
Note
Atlas Search index management in the Compass UI is available only for:Compass UI中的Atlas搜索索引管理仅适用于:
Atlas local deployments.Atlas本地部署。Deployments running MongoDB 7.0 or later.运行MongoDB 7.0或更高版本的部署。
Steps步骤
Find the index you want to use in your query查找要在查询中使用的索引
From the Indexes tab, click Search Indexes. Hover over the search index you want to use in your query.在“索引”选项卡中,单击“搜索索引”。将鼠标悬停在要在查询中使用的搜索索引上。
Open the aggregation pipeline builder打开聚合管道生成器
Click the Aggregate button that appears when you hover over your search index.将鼠标悬停在搜索索引上时,单击出现的“聚合”按钮。
Construct your query构建查询
By default, MongoDB Compass selects the 默认情况下,MongoDB Compass会为查询选择$search stage for your query. $search阶段。You can also select the 您还可以选择在查询中使用的$searchMeta stage to use in your query. $searchMeta阶段。If you are using a 如果在查询中使用vectorSearch type index in your query, you can use the $vectorSearch stage.vectorSearch类型的索引,则可以使用$vectorSearch阶段。
Note
If you use the 如果使用$search, $searchMeta, or $vectorSearch stage, it must be the first stage in your aggregation pipeline. $search、$searchMeta或$vectorSearch阶段,则它必须是聚合管道中的第一阶段。To combine vector and full-text search in the same pipeline, perform a hybrid search. 要在同一管道中组合矢量搜索和全文搜索,请执行混合搜索。For more information, see How to Perform Hybrid Search.有关更多信息,请参阅如何执行混合搜索。