本文内容

选择定价层并预配搜索服务后，下一步是有选择性地增加服务使用的副本或分区数目。After you choose a pricing tier and provision a search service, the next step is to optionally increase the number of replicas or partitions used by your service.每一层提供固定数量的计费单位。Each tier offers a fixed number of billing units.本文介绍如何通过分配这些单位来实现最佳配置，根据查询执行、索引和存储的要求做出平衡。This article explains how to allocate those units to achieve an optimal configuration that balances your requirements for query execution, indexing, and storage.

在“基本”层或者某个“标准”层或“内存优化”层中设置服务时，可以使用资源配置。Resource configuration is available when you set up a service at the Basic tier or one of the Standard or Storage Optimized tiers.对于这些层中的服务，购买的容量以搜索单位 (SU) 为增量，其中每个分区和副本被视为一个 SU。For services at these tiers, capacity is purchased in increments of search units (SUs) where each partition and replica counts as one SU.

使用的 SU 越少，帐单费用也就相应地越少。Using fewer SUs results in a proportionally lower bill.只要设置服务，就会产生费用。Billing is in effect for as long as the service is set up.如果暂时不使用某个服务，避免计费的唯一方法就是删除该服务，需要该服务时再重新创建。If you are temporarily not using a service, the only way to avoid billing is by deleting the service and then re-creating it when you need it.

备注

删除某个服务会删除该服务上的所有内容。Deleting a service deletes everything on it.Azure 搜索中没有用于备份和还原持久化搜索数据的设施。There is no facility within Azure Search for backing up and restoring persisted search data.若要在新服务上重新部署现有索引，应当运行最初用来创建和加载该索引的程序。To redeploy an existing index on a new service, you should run the program used to create and load it originally.

术语：副本和分区Terminology: replicas and partitions

副本和分区是支持搜索服务的主要资源。Replicas and partitions are the primary resources that back a search service.

是搜索服务的实例，主要用于对查询操作进行负载均衡。Instances of the search service, used primarily to load balance query operations.每个副本始终托管索引的一个副本。Each replica always hosts one copy of an index.如果有 12 个副本，服务中会加载每个索引的 12 个副本。If you have 12 replicas, you will have 12 copies of every index loaded on the service.

备注

无法直接操作或管理哪些索引在副本上运行。There is no way to directly manipulate or manage which indexes run on a replica.每个副本托管索引的一个副本，这是服务体系结构的一部分。One copy of each index on every replica is part of the service architecture.

如何分配副本和分区How to allocate replicas and partitions

在 Azure 搜索中，最初为服务分配了由一个分区和一个副本组成的最低级别的资源。In Azure Search, a service is initially allocated a minimal level of resources consisting of one partition and one replica.如果层支持这样做，可以递增方式调整计算资源：需要更多的存储和 I/O 时增加分区，或者增加副本来应对较大的查询卷或提供较好的性能。For tiers that support it, you can incrementally adjust computational resources by increasing partitions if you need more storage and I/O, or add more replicas for larger query volumes or better performance.单个服务必须具有足够的资源才能处理所有工作负荷（索引和查询）。A single service must have sufficient resources to handle all workloads (indexing and queries).无法在多个服务之间细分工作负荷。You cannot subdivide workloads among multiple services.

若要增加或更改副本和分区的分配，建议使用 Azure 门户。To increase or change the allocation of replicas and partitions, we recommend using the Azure portal.该门户针对允许的组合强制实施限制，使其低于上限。The portal enforces limits on allowable combinations that stay below maximum limits.如果需要使用基于脚本或基于代码的预配方法，Azure PowerShell 或管理 REST API 是替代的解决方案。If you require a script-based or code-based provisioning approach, the Azure PowerShell or the Management REST API are alternative solutions.

一般而言，搜索应用程序所需的副本数多过分区数，尤其是在服务操作偏向于查询工作负荷的情况下。Generally, search applications need more replicas than partitions, particularly when the service operations are biased toward query workloads.高可用性部分将解释原因。The section on high availability explains why.

在“设置”中，打开“规模”页以修改副本和分区。In Settings, open the Scale page to modify replicas and partitions.

以下屏幕截图显示了预配有一个副本和分区的标准服务。The following screenshot shows a standard service provisioned with one replica and partition.底部的公式指示正在使用多少个搜索单位 (1)。The formula at the bottom indicates how many search units are being used (1).如果单位价格为 $100（非实际价格），则运行此服务的每月成本平均为 $100。If the unit price was $100 (not a real price), the monthly cost of running this service would be $100 on average.

使用滑块增加或减少分区数。Use the slider to increase or decrease the number of partitions.底部的公式指示正在使用多少个搜索单位。The formula at the bottom indicates how many search units are being used.

此示例各使用一个副本和分区将容量翻倍。This example doubles capacity, with two replicas and partitions each.请注意搜索单位计数；现在有 4 个搜索单位，因为计费公式是副本数乘以分区数 (2 x 2)。Notice the search unit count; it is now four because the billing formula is replicas multiplied by partitions (2 x 2).将容量翻倍不仅仅会使运行服务的成本翻倍。Doubling capacity more than doubles the cost of running the service.如果搜索单位的成本是 $100，则新的每月费用将是 $400。If the search unit cost was $100, the new monthly bill would now be $400.

有关每个层的当前单位成本，请访问定价页。For the current per unit costs of each tier, visit the Pricing page.

单击“保存”以确认所做的更改。Click Save to confirm the changes.

更改容量需要花费几个小时才能完成。Changes in capacity take several hours to complete.一旦启动更改过程，就无法将其取消；系统不会实时监视副本和分区的调整。You cannot cancel once the process has started and there is no real-time monitoring for replica and partition adjustments.但是，在更改过程中，会一直显示以下消息。However, the following message remains visible while changes are underway.

分区和副本组合Partition and replica combinations

“基本”服务可以包含一个分区以及最多三个副本，上限为三个 SU。A Basic service can have exactly one partition and up to three replicas, for a maximum limit of three SUs.唯一可调整的资源是副本。The only adjustable resource is replicas.至少需要两个副本才能实现查询的高可用性。You need a minimum of two replicas for high availability on queries.

所有“标准”和“存储优化”搜索服务可以采用副本和分区的以下组合，但不能超过 36 个 SU 的限制。All Standard and Storage Optimized search services can assume the following combinations of replicas and partitions, subject to the 36-SU limit.

1 个分区1 partition

2 个分区2 partitions

3 个分区3 partitions

4 个分区4 partitions

6 个分区6 partitions

12 个分区12 partitions

1 个副本1 replica

1 个 SU1 SU

2 SU2 SU

3 SU3 SU

4 SU4 SU

6 SU6 SU

12 SU12 SU

2 个副本2 replicas

2 SU2 SU

4 SU4 SU

6 SU6 SU

8 SU8 SU

12 SU12 SU

24 SU24 SU

3 个副本3 replicas

3 SU3 SU

6 SU6 SU

9 SU9 SU

12 SU12 SU

18 SU18 SU

36 个 SU36 SU

4 个副本4 replicas

4 SU4 SU

8 SU8 SU

12 SU12 SU

16 SU16 SU

24 SU24 SU

不可用N/A

5 副本5 replicas

5 SU5 SU

10 SU10 SU

15 SU15 SU

20 SU20 SU

30 SU30 SU

不可用N/A

6 个副本6 replicas

6 SU6 SU

12 SU12 SU

18 SU18 SU

24 SU24 SU

36 个 SU36 SU

不可用N/A

12 副本12 replicas

12 SU12 SU

24 SU24 SU

36 个 SU36 SU

不可用N/A

不可用N/A

不可用N/A

Azure 网站上详细说明了 SU、定价和容量。SUs, pricing, and capacity are explained in detail on the Azure website.有关详细信息，请参阅 Pricing Details（定价详细信息）。For more information, see Pricing Details.

备注

副本数和分区数必须能被 12 整除（具体而言，为 1、2、3、4、6、12）。The number of replicas and partitions divides evenly into 12 (specifically, 1, 2, 3, 4, 6, 12).这是因为，Azure 搜索将每个索引预先分割为 12 个分片，以便将其平均分散到所有分区。This is because Azure Search pre-divides each index into 12 shards so that it can be spread in equal portions across all partitions.例如，如果服务有三个分区，而你创建了新索引，则每个分区将包含该索引的四个分片。For example, if your service has three partitions and you create an index, each partition will contain four shards of the index.Azure 搜索为索引分片的方法属于实现细节，在将来的版本中可能发生变化。How Azure Search shards an index is an implementation detail, subject to change in future releases.尽管目前的分区数为 12，但请不要料想将来该数字永远都是 12。Although the number is 12 today, you shouldn't expect that number to always be 12 in the future.

高可用性High availability

由于扩展的过程比较简单而且相对较快，因此我们通常建议从一个分区以及一个或两个副本开始，并随着不断构建查询卷而进行扩展。Because it's easy and relatively fast to scale up, we generally recommend that you start with one partition and one or two replicas, and then scale up as query volumes build.查询工作负荷主要是在副本上运行。Query workloads run primarily on replicas.如果需要更高的吞吐量或高可用性，也许需要增加副本。If you need more throughput or high availability, you will probably require additional replicas.

针对高可用性的一般建议是：General recommendations for high availability are:

对于只读工作负荷（查询），需要有两个副本才能实现高可用性Two replicas for high availability of read-only workloads (queries)

对于读/写工作负荷（查询以及添加、更新或删除单个文档时的索引编制），需有三个或更多个副本才能实现高可用性Three or more replicas for high availability of read/write workloads (queries plus indexing as individual documents are added, updated, or deleted)

基本层最多能有一个分区和三个副本。Basic tier tops out at one partition and three replicas.如果希望灵活地立即响应对索引编制和查询吞吐量的需求波动，请考虑使用标准层中的一个。If you want the flexibility to immediately respond to fluctuations in demand for both indexing and query throughput, consider one of the Standard tiers.如果你发现存储要求的增长速度大大超过了可用的吞吐量，请考虑使用某个“存储优化”层。If you find your storage requirements are growing much more rapidly than your query throughput, consider one of the Storage Optimized tiers.

重建期间的索引可用性Index availability during a rebuild

Azure 搜索的高可用性与查询以及不涉及重建索引的索引更新相关。High availability for Azure Search pertains to queries and index updates that don't involve rebuilding an index.如果删除字段、更改数据类型或重命名字段，则需要重建索引。If you delete a field, change a data type, or rename a field, you will need to rebuild the index.要重建索引，必须删除该索引，重新创建该索引，并重新加载数据。To rebuild the index, you must delete the index, re-create the index, and reload the data.

备注

可将新字段添加到 Azure 搜索索引，而无需重建索引。You can add new fields to an Azure Search index without rebuilding the index.对于索引中已存在的所有文档，新字段的值将为 null。The value of the new field will be null for all documents already in the index.

要让索引在重建期间保持可用，相同的服务中必须存在不同名的索引副本，或者不同的服务中存在同名的索引，并在代码中提供重定向或故障转移逻辑。To maintain index availability during a rebuild, you must have a copy of the index with a different name on the same service, or a copy of the index with the same name on a different service, and then provide redirection or failover logic in your code.

灾难恢复Disaster recovery

目前没有任何内置的机制可实现灾难恢复。Currently, there is no built-in mechanism for disaster recovery.添加分区或副本并不是实现灾难恢复目标的正确策略。Adding partitions or replicas would be the wrong strategy for meeting disaster recovery objectives.最常见的方法是通过在另一区域中设置另一个搜索服务，在服务级别添加冗余。The most common approach is to add redundancy at the service level by setting up a second search service in another region.与索引重建期间的可用性一样，重定向或故障转移逻辑必须来自代码。As with availability during an index rebuild, the redirection or failover logic must come from your code.

使用副本提高查询性能Increase query performance with replicas

如果出现查询延迟，则表明需要增加副本。Query latency is an indicator that additional replicas are needed.一般而言，改善查询性能的第一步是增加此类资源。Generally, a first step toward improving query performance is to add more of this resource.添加副本时，将有更多的索引副本联机，可支持更大的查询工作负荷，通过多个副本对请求进行负载均衡。As you add replicas, additional copies of the index are brought online to support bigger query workloads and to load balance the requests over the multiple replicas.

我们无法提供可靠的每秒查询数 (QPS) 预测：查询性能取决于查询和竞争工作负荷的复杂性。We cannot provide hard estimates on queries per second (QPS): query performance depends on the complexity of the query and competing workloads.尽管添加副本会明显提高性能，但结果不一定有线性改善：添加三个副本并不保证带来三倍的吞吐量。Although adding replicas clearly results in better performance, the result is not strictly linear: adding three replicas does not guarantee triple throughput.

使用分区提高索引性能Increase indexing performance with partitions

需要以近乎实时的速度刷新数据的搜索应用程序，需要的分区数在比例上要多于副本。Search applications that require near real-time data refresh will need proportionally more partitions than replicas.添加分区可将读/写操作分配到更多的计算资源。Adding partitions spreads read/write operations across a larger number of compute resources.此外，还能提供更多磁盘空间来存储更多的索引和文档。It also gives you more disk space for storing additional indexes and documents.

索引越大，查询所需的时间就越长。Larger indexes take longer to query.因此，可能发现，每次增加分区都需要按比例少量增加副本。As such, you might find that every incremental increase in partitions requires a smaller but proportional increase in replicas.查询和查询卷的复杂性影响查询执行的速度。The complexity of your queries and query volume will factor into how quickly query execution is turned around.