You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _api-reference/cluster-api/cluster-awareness.md
+84-51Lines changed: 84 additions & 51 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
layout: default
3
3
title: Cluster routing and awareness
4
-
nav_order: 20
4
+
nav_order: 50
5
5
parent: Cluster APIs
6
6
has_children: false
7
7
redirect_from:
@@ -13,111 +13,144 @@ redirect_from:
13
13
**Introduced 1.0**
14
14
{: .label .label-purple }
15
15
16
-
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.
16
+
To control how search traffic is routed across zones, you can assign weights to awareness attribute values. This is useful for zonal deployments, heterogeneous clusters, or routing traffic away from unhealthy zones.
17
+
18
+
## Prerequisites
19
+
20
+
Before using this API, you must configure cluster awareness attributes and node attributes. This can be done either in the `opensearch.yml` file or through the Cluster Settings API.
21
+
22
+
For example, to configure `zone` and `rack` awareness attributes using `opensearch.yml`, specify them as a comma-separated list:
For more information about OpenSearch settings, see [Configuring OpenSearch]({{site.url}}{{site.baseurl}}/install-and-configure/configuring-opensearch/).
17
42
18
43
## Endpoints
19
44
20
45
```json
21
46
PUT /_cluster/routing/awareness/<attribute>/weights
22
47
GET /_cluster/routing/awareness/<attribute>/weights?local
23
48
GET /_cluster/routing/awareness/<attribute>/weights
The following table lists the available path parameters. All path parameters are optional.
55
+
56
+
Parameter | Data type | Description
29
57
:--- | :--- | :---
30
-
attribute | String | The name of the awareness attribute, usually `zone`. The attribute name must match the values listed in the request body when assigning weights to zones.
58
+
`<attribute>` | String | The name of the configured awareness attribute (for example, `zone`). The attribute specified in the path determines which awareness attribute the weights apply to.
31
59
32
-
## Request body fields
60
+
## Query parameters
33
61
34
-
Parameter | Type | Description
35
-
:--- | :--- | :---
36
-
weights | JSON object | Assigns 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.
37
-
_version | String | Implements 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.
62
+
The following table lists the available query parameters. All query parameters are optional.
38
63
64
+
| Parameter | Data type | Description |
65
+
| :--- | :--- | :--- |
66
+
|`local`| Boolean | Can be provided in a `GET` request only. If `true`, the request retrieves information from the node that receives the request instead of from the cluster manager node. Default is `false`.|
39
67
40
-
In the following example request body, `zone_1` and `zone_2` receive 50 requests each, whereas `zone_3` is prevented from receiving requests:
68
+
## Request body fields
41
69
42
-
```
43
-
{
44
-
"weights":
45
-
{
46
-
"zone_1": "5",
47
-
"zone_2": "5",
48
-
"zone_3": "0"
49
-
}
50
-
"_version" : 1
51
-
}
52
-
```
70
+
The following table lists the available request body fields for the `PUT` and `DELETE` methods.
53
71
54
-
## Example requests
72
+
| Parameter | Data type | Applicable method | Description |
73
+
| :--- | :--- | :--- | :--- |
74
+
|`weights`| Object |`PUT`| Specifies custom weights for the awareness attribute values. The weights influence how search requests are distributed across zones or other awareness attribute values. Weights are relative and can use any ratio. For example, in a `2:3:5` ratio across three zones, 20%, 30%, and 50% of requests are routed to the respective zones. A weight of `0` excludes a zone from receiving search traffic. Required for the `PUT` method. |
75
+
|`_version`| Integer |`PUT`, `DELETE`| Used for optimistic concurrency control (OCC). Ensures that changes are applied only if the current version matches, preventing conflicting updates. The version is incremented after each succesful `PUT` or `DELETE` operation. To initiate concurrency control, you must set `_version` to `-1` in the initial request. Required for the `PUT` and `DELETE` methods. |
55
76
56
-
### Weighted round robin search
57
77
58
-
The following example request creates a roundrobin shard allocation for search traffic by using an undefined ratio:
78
+
## Example request: Weighted round-robin search
59
79
80
+
The following example request creates a round-robin shard allocation for search traffic between two zones while excluding a third zone from receiving any traffic:
60
81
61
82
```json
62
83
PUT /_cluster/routing/awareness/zone/weights
63
84
{
64
-
"weights":
65
-
{
66
-
"zone_1": "1",
67
-
"zone_2": "1",
68
-
"zone_3": "0"
69
-
}
70
-
"_version" : 1
85
+
"weights":
86
+
{
87
+
"zone_1": "1",
88
+
"zone_2": "1",
89
+
"zone_3": "0"
90
+
},
91
+
"_version" : -1
71
92
}
72
93
```
73
94
{% include copy-curl.html %}
74
95
96
+
After this request, the `_version` increments to `0`.
97
+
98
+
To create a shard allocation for multiple awareness attributes, send a separate request for each attribute.
75
99
76
-
### Getting weights for all zones
100
+
##Example request: Updating the configuration
77
101
78
-
The following examplerequest gets weights for all zones.
102
+
The `PUT` request fully replaces the existing weight configuration for the specified awareness attribute. Any values omitted in the request are removed from the configuration. For example, the following request updates the weights for zones 1 and 3 and removes zone 2:
79
103
80
104
```json
81
-
GET /_cluster/routing/awareness/zone/weights
105
+
PUT /_cluster/routing/awareness/zone/weights
106
+
{
107
+
"weights":
108
+
{
109
+
"zone_1": "2",
110
+
"zone_3": "1"
111
+
},
112
+
"_version" : 0
113
+
}
82
114
```
83
115
{% include copy-curl.html %}
84
116
117
+
After this request, the `_version` increments to `1`.
85
118
86
-
### Deleting weights
119
+
##Example request: Viewing the configuration
87
120
88
-
You can remove your weight ratio for each zone using the `DELETE` method:
121
+
To view the current weight configuration and its version, send the following request. Use the returned version number in subsequent update or delete requests:
89
122
90
123
```json
91
-
DELETE /_cluster/routing/awareness/zone/weights
124
+
GET /_cluster/routing/awareness/zone/weights
92
125
```
93
126
{% include copy-curl.html %}
94
127
95
-
## Example responses
96
-
97
-
OpenSearch typically responds with the following when successfully allocating shards:
128
+
## Example response
98
129
99
130
```json
100
131
{
101
-
"acknowledged": true
132
+
"weights": {
133
+
"zone_1": "2.0",
134
+
"zone_3": "1.0"
135
+
},
136
+
"_version": 1,
137
+
"discovered_cluster_manager": true
102
138
}
103
139
```
104
140
105
-
### Getting weights for all zone
141
+
##Example request: Deleting the configuration
106
142
107
-
OpenSearch responds with the weight of each zone:
143
+
To remove a weight configuration, provide the current version in a `DELETE` request:
108
144
109
145
```json
146
+
DELETE /_cluster/routing/awareness/zone/weights
110
147
{
111
-
"weights":
112
-
{
113
-
114
-
"zone_1": "1.0",
115
-
"zone_2": "1.0",
116
-
"zone_3": "0.0"
117
-
},
118
-
"_version":1
148
+
"_version": 1
119
149
}
150
+
```
151
+
{% include copy-curl.html %}
120
152
153
+
After this request, the `_version` increments to `2`.
0 commit comments