Cluster routing and awareness

Introduced 1.0

To control the distribution of search or HTTP traffic, you can use the weights per awareness attribute to control the distribution of search or HTTP traffic across zones. This is commonly used for zonal deployments, heterogeneous instances, and routing traffic away from zones during zonal failure.

Path and HTTP methods

  1. PUT /_cluster/routing/awareness/<attribute>/weights
  2. GET /_cluster/routing/awareness/<attribute>/weights?local
  3. GET /_cluster/routing/awareness/<attribute>/weights

Path parameters

ParameterTypeDescription
attributeStringThe name of the awareness attribute, usually zone. The attribute name must match the values listed in the request body when assigning weights to zones.

Request body fields

ParameterTypeDescription
weightsJSON objectAssigns weights to attributes within the request body of the PUT request. Weights can be set in any ratio, for example, 2:3:5. In a 2:3:5 ratio with 3 zones, for every 100 requests sent to the cluster, each zone would receive either 20, 30, or 50 search requests in a random order. When assigned a weight of 0, the zone does not receive any search traffic.
_versionStringImplements optimistic concurrency control (OCC) through versioning. The parameter uses simple versioning, such as 1, and increments upward based on each subsequent modification. This allows any servers from which a request originates to validate whether or not a zone has been modified.

In the following example request body, zone_1 and zone_2 receive 50 requests each, whereas zone_3 is prevented from receiving requests:

  1. {
  2. "weights":
  3. {
  4. "zone_1": "5",
  5. "zone_2": "5",
  6. "zone_3": "0"
  7. }
  8. "_version" : 1
  9. }

Example requests

The following example request creates a round robin shard allocation for search traffic by using an undefined ratio:

  1. PUT /_cluster/routing/awareness/zone/weights
  2. {
  3. "weights":
  4. {
  5. "zone_1": "1",
  6. "zone_2": "1",
  7. "zone_3": "0"
  8. }
  9. "_version" : 1
  10. }

copy

Getting weights for all zones

The following example request gets weights for all zones.

  1. GET /_cluster/routing/awareness/zone/weights

copy

Deleting weights

You can remove your weight ratio for each zone using the DELETE method:

  1. DELETE /_cluster/routing/awareness/zone/weights

copy

Example responses

OpenSearch typically responds with the following when successfully allocating shards:

  1. {
  2. "acknowledged": true
  3. }

Getting weights for all zone

OpenSearch responds with the weight of each zone:

```json { “weights”: {

  1. "zone_1": "1.0",
  2. "zone_2": "1.0",
  3. "zone_3": "0.0"
  4. },
  5. "_version":1 }

Next steps