Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs 菜单
Docs 主页
/ /

MongoDB Search 部署选项

您可以使用不同的部署类型、云提供商和集群层来构建集群,以满足预生产或生产环境的需求。使用这些建议来选择部署类型、云提供商和地区以及用于执行向量搜索的集群和搜索层。

environment
部署类型
集群层
云提供商地区
节点架构

测试查询

Flex or dedicated cluster

Local deployment
Free cluster, Flex, or higher tier

N/A
All


N/A

MongoDB和Atlas Search进程在同一节点上运行

应用程序原型设计

专用集群,分片或非分片

M10M20 或更高层级

所有

MongoDB和Atlas Search进程在同一节点上运行

生产

具有独立搜索节点(分片或非分片)的专用集群

M10 或更高集群层以及 S20 或更高搜索层级

AWSAzure 某些 区域 或所有地区的 Google Cloud

MongoDB和Atlas Search进程在不同节点上运行

以下各节描述了每个环境:

为了测试您的搜索查询和为您的应用程序创建原型,我们建议采用以下部分中描述的部署类型和节点架构。

此配置最适合以下用例:

  • 要索引的总文档少于 2M

  • 少于 10 GB 的索引数据

  • 在 7 天内少于 10,000 次查询

如果使用量超过列出的值,请迁移至专用搜索节点。

以下各节更详细地描述了此节点架构。

部署类型

要在云中的集群上测试MongoDB搜索查询,您可以部署Flex 或专用集群。

To test MongoDB Search queries locally, create a local Atlas deployment using the Atlas CLI. This could be a single-node replica set hosted on your local computer. Local deployments are limited by the CPU, memory, and storage resources of your local machine. When your application is ready for production, migrate your local Atlas deployment to a production environment.

Cluster Tiers

要测试MongoDB搜索查询,请使用免费集群(以前称为 M0)和 Flex 集群。

For prototyping your application, use dedicated M10, M20, and higher tier clusters or deploy dedicated Search Nodes for workload isolation. When your application is ready for production and to handle large datasets, scale to higher tiers.

云提供商和地区

使用任何受支持的云提供商区域。

The cloud provider and region that you choose affect the configuration options available for the cluster tiers and the cost of running the cluster.

对于测试和原型环境,我们建议采用MongoDB进程和MongoDB搜索进程在同一节点上运行的节点架构。在此部署模型的下图中, MongoDB Search mongot进程与 mongod 一起在Atlas 集群中的每个节点上运行,并且它们股票相同的资源。

MongoDB Search 架构

默认下,当您创建第一个MongoDB Search索引时, Atlas会在运行 mongod进程的同一节点上启用MongoDB Search mongot进程。

运行查询时, MongoDB Search 会使用配置的读取偏好(read preference)来识别运行查询的节点。查询首先进入MongoDB进程,对于副本集集群为 mongod,对于分片集群为 mongos

For a replica set cluster, the mongod process routes the query to the mongot on the same node. For sharded clusters, your cluster data is partitioned across mongod instances (shards) and each mongot process can only access the data on the mongod instance on the same node. Therefore, you can't run MongoDB Search queries that target a particular shard. mongos routes the query to all shards, making these scatter gather queries. If you use zones to distribute a sharded collection over a subset of the shards in the cluster, MongoDB Search routes the query to the zone that contains the shards for the collection that you are querying and runs your $search queries on just the shards where the collection is located.

将查询路由到MongoDB搜索 mongot进程后,mongot进程执行搜索和评分,并将匹配结果的文档ID 和其他搜索元数据返回相应的 mongod进程。然后,mongod进程对匹配结果隐式执行完整文档查找,并将结果返回客户端。如果在查询中使用 $search 并发 选项, MongoDB Search 将启用查询内并行机制。要学习;了解更多信息,请参阅跨分段并行查询执行。

要了解有关 mongot 过程的更多信息,请参阅查询处理。

您可以在MongoDB Search索引中定义存储的源字段,以便 mongot进程可以在 mongot 上存储指定的字段。然后,您可以在MongoDB Search查询中使用 returnStoredSource 选项,直接从 mongot 检索匹配文档的检索字段,而不是在数据库中执行完整文档查找。

提示

启用MongoDB Search 后,您可以使用完全托管的托管搜索引擎(自动同步到数据库)轻松地在数据上构建搜索。MongoDB Search 提供了一种丰富的查询语言,该语言使用MongoDB Search聚合管道阶段(例如用于全文搜索的$search$searchMeta 以及与其他MongoDB聚合管道阶段结合使用的 $vectorSearch 进行语义搜索)以及基于分数的结果排名。

根据为集群预配的资源,在同一节点上部署这两个进程可能比在单独的专用节点上运行搜索进程更具成本效益。

您可能会遇到数据库mongod 和搜索mongot 进程之间的资源争用。这可能会对索引性能和查询延迟产生负面影响。支持将生产就绪应用程序及其搜索工作负载迁移到专用搜索节点。

在集群上启用MongoDB Search 时,无需支付额外费用或收费。但是,您可能会发现大型索引集合或索引定义的集群资源利用率有所增加。

由于 mongodmongot 进程在同一节点上运行,因此在某些情况下,mongot 可能不可用。 下表描述了可能的原因:

原因
说明

cluster Tier Scaling - Network Storage

当您向上或向下扩展集群时, Atlas会预配一个新实例。 实例准备就绪后, Atlas会附加网络存储并在新节点上启动 mongodmongot

如果 mongodmongot 之前启动,则MongoDB搜索查询将失败,直到 mongot运行。

cluster Tier Scaling - Local SSD

当您使用本地固态硬盘扩展Atlas 集群时,您无法保留存储并将其重新连接到新节点。因此, Atlas会执行初始同步以重建搜索索引。在初始同步完成之前,搜索查询将失败。

Lucene降级

在需要降级Lucene 的极少数情况下,您可能无法读取较新的Lucene索引格式。

存储调整

您可以保留连接到Atlas 集群节点的网络存储。 这样,您就可以在不影响mongot 的情况下扩大或缩小卷容量。

但是,在某些区域、当集群使用本地 NVMe 磁盘或其他罕见情况下,可能无法保留网络存储。在这些情况下, Atlas会执行初始同步,搜索查询将失败,直到初始同步完成。

mongot 版本更新

mongot 版本更新期间, Atlas会停止旧版本的 mongot 并启动新版本。 在此短暂期间,搜索查询将失败,直到新的 mongot 启动。

新的 mongod 节点

当您向集群添加新节点时, Atlas会执行初始同步以创建搜索索引。 在初始同步完成之前,使用新 mongod节点的搜索查询将失败。

实例重启或替换

  • 您的Atlas实例可能会在新的安全策略推出期间或您的云提供商要求时重新启动。 当Atlas重新启动时,如果 mongodmongot 之前启动,则搜索查询将失败,直到 mongot运行。

  • 如果您的硬件不正常或迁移了系统架构,您的Atlas实例可能需要更换。 替换实例时,mongot 会执行初始同步,而搜索查询将失败,直到初始同步完成。

mongot 重新启动

每当由于配置更改而导致 mongot 进程重新启动时,搜索查询均会失败,直到 mongot 变为可用为止。

对于您的生产就绪应用程序,我们建议使用以下各节中描述的部署类型和节点架构。

此配置最适合以下用例:

  • 如果您选择将现有测试环境迁移到生产环境,请向集群添加专用搜索节点。要学习;了解更多信息,请参阅迁移到专用搜索节点。

  • 如果您从头开始创建新的生产部署,请确保在MongoDB Search 可用的地区和分区中使用支持MongoDB Search 的 M10 或更大层级的集群,并为您的环境添加专用的 Search Nodes。要学习;了解更多信息,请参阅添加专用搜索节点。

部署类型

对于生产就绪型应用程序,请使用 M10M20 和更高的专用集群层级。这些更高层级的集群可以处理大型数据集和生产工作负载。

We recommend that you also deploy dedicated Search Nodes. If your search requirements increase, you can scale up your search deployment independently of scaling up the MongoDB nodes.

云提供商和地区

Use Search Nodes in all Google Cloud regions and in a subset of AWS and Azure regions. You must select a cloud provider and region where Search Nodes are available for your deployment.

All cluster tiers are available in supported cloud provider regions. The cloud provider and region that you choose affect the configuration options and search tiers available for the cluster and the cost of running the cluster.

对于生产环境,我们建议采用一种节点架构,其中MongoDB进程和MongoDB搜索进程在单独的节点上运行。要部署单独的搜索节点,请参阅迁移到专用搜索节点。

在此部署模型的下图中, MongoDB Search mongot进程在专用搜索节点上运行,这些节点与运行 mongod进程的集群节点是分开的。

独立搜索节点架构

Atlas 为每个集群或集群上的每个分片部署搜索节点。例如,如果您为具有三个分片的集群部署两个搜索节点,则 Atlas 会部署六个搜索节点(每个分片两个)。您还可以配置搜索节点的数量,以及为每个搜索节点配置的资源量。

When you deploy separate Search Nodes, Atlas automatically assigns a mongod for each mongot for indexing. The mongot communicates with the mongod to listen for and sync index changes for the indexes that it stores. MongoDB Search indexes and processes your queries similar to a deployment where both the mongod and mongot processes run on the same node. To learn more, see Supported Clients and Queries and Indexes. To learn more about deploying Search Nodes separately, see Search Nodes for Workload Isolation.

当您迁移到搜索节点时,Atlas 会部署搜索节点,但不会在节点上提供查询,直到它在搜索节点上的集群上成功构建所有索引。当 Atlas 在新节点上构建索引时,它会继续使用集群节点上的索引提供查询。仅当 Atlas 在搜索节点上成功构建索引并删除集群节点上的索引后,它才会开始从搜索节点提供查询服务。

注意

Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled Encryption at Rest using Customer Key Management, Atlas provides the following optimizations:

  • When you scale your search nodes, Atlas uses a recent copy of your index in S3, Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  • 对于现有节点,Atlas 会定期获取并上传新的索引文件增量列表。Atlas 将索引文件保留最多十四 (14) 天。

运行查询时,查询会根据配置的读取偏好(read preference)路由到 mongodmongod进程通过同一节点上的负载负载均衡器路由搜索查询,这会将请求分发到所有 mongot 进程。

MongoDB Search mongot进程执行搜索和评分,并将匹配结果的文档ID 和元数据返回给 mongod。然后,mongod 对匹配结果执行完整文档查找,并将结果返回给客户端。如果在查询中使用 $search 并发 选项, MongoDB Search 将启用查询内并行机制。要学习;了解更多信息,请参阅跨分段并行查询执行。

If you delete all the Search Nodes on your cluster, there will be an interruption in processing your search query results. To learn more, see Modify a Cluster. If you delete your Atlas cluster, Atlas pauses and then deletes all associated MongoDB Search deployments (mongot processes).

您可以在MongoDB Search索引中定义存储的源字段,以便 mongot进程可以在 mongot 上存储指定的字段。然后,您可以在MongoDB Search查询中使用 returnStoredSource 选项,直接从 mongot 检索匹配文档的检索字段,而不是在数据库中执行完整文档查找。

单独部署搜索节点具有以下优势:

高可用性
当您部署单独的搜索节点时,Atlas 会强制使用至少两个搜索节点,以确保在出现故障或中断时您的工作负载保持运行状态,将停机时间降至最低。
可扩展性

当您部署单独的搜索节点时,您可以在不依赖 MongoDB 集群的情况下独立扩展存储和计算能力。这使您可以独立于 MongoDB 扩展查询负载。

要扩展扩展搜索节点,请增加或减少搜索节点的数量。您可以预配最少 2 个、最多 32 个搜索节点。为了平衡查询负载, MongoDB Search 将搜索查询分布在所有可用的搜索节点上。

要垂直扩展搜索节点,请选择支持您全文工作负载的不同搜索层级、CPU、RAM和存储配置。

性能

在部署专用搜索节点时,您可以提高 mongodmongot 进程的性能和资源利用率,并消除这些进程之间的资源争用。

专用搜索节点支持并发分段搜索,这允许MongoDB Search 同时搜索多个索引段。在某些情况下,使用并发分段搜索可缩短查询响应时间。

工作负载隔离
部署专用搜索节点不会直接影响到主数据库节点的数据传输。搜索节点与主数据库操作分开处理搜索查询,从而提供工作负载隔离性,而您只需为搜索节点和数据库节点之间的流量支付网络费用。

如要确定搜索节点的内存需求,请参考以下 Atlas 指标:

  • 搜索索引的大小

  • 搜索节点上的总 RAM

假设某个应用程序的搜索索引为 10GB,而搜索节点的总 RAM 为 4 GB。在这种情况下,如果其他进程使用了 1 GB RAM,而只有 3 GB 可用于索引数据,则剩余的 7 GB 索引数据(10 GB - 3 GB = 7 GB)将根据需要从磁盘分页读取。频繁从磁盘进行分页会导致页面错误、磁盘 I/O 和 CPU IOWait 增加,从而造成性能下降。

如果您使用具有更多 RAM 的更高搜索集群层(例如 8GB 或更多),这将允许 Atlas 从内存中提供搜索索引的大部分数据,最大限度地减少磁盘读取和页面错误,从而提高性能。

注意

用于搜索节点的本地固态硬盘需要 20% 的存储开销来支持索引操作。

MongoDB supports separate Search Nodes on dedicated (M10 or higher) clusters. Search Nodes are deployed on compute-intensive instances with high-performance local storage. You must deploy a minimum of two nodes. You will be billed daily for hourly resource usage per node. To learn more, see Search Node Costs.

默认下, MongoDB和搜索进程在同一节点上运行。在这种架构中,客户管理的加密适用于数据库数据,但不适应用搜索索引。

启用专用搜索节点后,搜索进程将在单独的节点上运行。这允许您启用搜索节点数据加密,以便您可以使用相同的客户托管密钥对数据库数据和搜索索引进行加密,以实现全面的加密覆盖范围。

注意

数据库节点和搜索节点使用不同的加密方法以及相同的客户托管密钥。数据库节点使用WiredTiger加密存储引擎,而搜索节点则在磁盘级别使用加密。

如要了解更多信息,请参阅启用搜索节点的客户密钥管理。

重要

KMS 提供商均提供此功能,但搜索节点必须位于 AWS 上。

向新集群添加专用搜索节点可以使您:

  • Change the size and scale of your search deployment independently from your database deployment.

  • 消除在同一节点上运行 MongoDB 数据库和搜索进程的集群中可能出现的资源争用。

要添加专用搜索节点:

  1. Create your cluster as an M10 or higher tier in a cloud provider and region that supports node isolation. To learn more, see Create a Cluster.

    Dedicated Search Nodes are supported only for M10 and higher cluster tiers and in cloud provider regions that support node isolation.

  2. Enable Search Nodes for workload isolation and Configure Search Nodes.

要从暂存迁移到生产并添加专用搜索节点,请对现有的暂存和原型部署进行以下更改:

  1. If your deployment uses a Flex cluster, change the cluster tier to a higher tier. Dedicated Search Nodes are supported only for M10 and higher cluster tiers.

  2. Deploy your cluster in regions where Search Nodes are also available. Dedicated Search Nodes are available on a subset of the AWS and Azure regions and in all supported Google Cloud regions. If your existing cluster is hosted in regions where Search Nodes aren't available, migrate your cluster to regions where Search Nodes are available. To learn more, see Cloud Provider Regions that Support Node Isolation.

  3. 启用 Search Nodes for workload isolation 并配置搜索节点。要学习;了解更多信息,请参阅添加搜索节点

    部署专用搜索节点时,会执行以下操作顺序:

    • Atlas 在搜索节点上构建搜索索引,并从集群节点中移除这些索引。

    • Atlas 将搜索查询路由到搜索节点。

    • MongoDB Search 使用搜索索引为集群提供查询提供服务。

如果您部署 mongot 以与 mongod 一起运行并且未配置搜索节点,则 mongot 可能会在以下任何事件中终止并返回 Failed to Execute search Command 错误:

  • 扩展集群

  • 节点故障转移

  • 正在升级 mongot

如果您在专用搜索节点上部署 mongotmongod 将使用代理仅将搜索查询路由到 mongot 进程处于活动状态的健康节点。

后退

查询

在此页面上