Skip to content

Commit d7173f1

Browse files
adding shard allocation API docs and linking to shrink api docs (#10802)
* adding shard allocation API docs and linking to shrink api docs Signed-off-by: Anton Rubin <[email protected]> * Apply suggestions from code review Signed-off-by: Nathan Bower <[email protected]> --------- Signed-off-by: Anton Rubin <[email protected]> Signed-off-by: Nathan Bower <[email protected]> Co-authored-by: Nathan Bower <[email protected]>
1 parent bcdee10 commit d7173f1

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
layout: default
3+
title: Shard allocation
4+
parent: Index APIs
5+
nav_order: 137
6+
---
7+
8+
# Shard allocation filtering
9+
10+
Shard allocation filtering lets you constrain where shards for an index are placed by matching node attributes. You can use it to pin shards to certain nodes, avoid nodes, or require specific hardware or zones. Shards are only allocated to nodes that satisfy all active filters, including index-level shard allocation filtering and [cluster-level routing awareness]({{site.url}}{{site.baseurl}}/api-reference/cluster-api/cluster-awareness/).
11+
12+
## Endpoints
13+
14+
```json
15+
PUT /<index>/_settings
16+
GET /<index>/_settings
17+
```
18+
19+
## Path parameters
20+
21+
The following table lists the available path parameters. All path parameters are optional.
22+
23+
Parameter | Data type | Description
24+
:--- | :--- | :---
25+
`<index>` | String | One or more comma-separated indexes from which to update or read settings. Use `_all` or `*` to target all indexes. |
26+
27+
## Built-in and custom attributes
28+
29+
You can filter on built‑in attributes or any custom node attribute you define. For example, custom attribute can be defined by adding `node.attr.zone: zone-a` in `opensearch.yml`. The following built‑in attributes are supported.
30+
31+
Attribute | Description
32+
:--- | :---
33+
`_name` | Match by node name.
34+
`_host_ip` | Match by host IP address.
35+
`_publish_ip` | Match by publish IP address.
36+
`_ip` | Match either `_host_ip` or `_publish_ip`.
37+
`_host` | Match by hostname.
38+
`_id` | Match by node ID.
39+
`_tier` | Match nodes by data tier role.
40+
41+
## Filter types
42+
43+
Use the following index settings.
44+
45+
Setting | Effect
46+
:--- | :---
47+
`index.routing.allocation.include.<attr>` | Allocate shards to nodes that match **any** of the provided values.
48+
`index.routing.allocation.exclude.<attr>` | **Do not** allocate shards to nodes that match **any** of the provided values.
49+
`index.routing.allocation.require.<attr>` | Allocate shards **only** to nodes that match **all** of the provided values.
50+
51+
## Example requests
52+
53+
The following examples demonstrate the different ways to use shard allocation filters.
54+
55+
### Allocate an index only to a specific zone
56+
57+
Use the following command to allocate an index to nodes in `zone-a`:
58+
59+
```json
60+
PUT /test-index/_settings
61+
{
62+
"index.routing.allocation.require.zone": "zone-a"
63+
}
64+
```
65+
{% include copy-curl.html %}
66+
67+
### Allocate to a subset of nodes by IPs
68+
69+
```json
70+
PUT /test-index/_settings
71+
{
72+
"index.routing.allocation.include._ip": "10.0.0.12,10.0.0.13"
73+
}
74+
```
75+
{% include copy-curl.html %}
76+
77+
### Exclude an index from the node
78+
79+
The following command excludes an index from node `data-node-3`:
80+
81+
```json
82+
PUT /test-index/_settings
83+
{
84+
"index.routing.allocation.exclude._name": "data-node-3"
85+
}
86+
```
87+
{% include copy-curl.html %}
88+
89+
### Combine filters
90+
91+
The following command configures required rack but excludes node `data-node-7`:
92+
93+
```json
94+
PUT /test-index/_settings
95+
{
96+
"index": {
97+
"routing.allocation.require.rack": "r1",
98+
"routing.allocation.exclude._name": "data-node-7"
99+
}
100+
}
101+
```
102+
{% include copy-curl.html %}
103+
104+
### Clear a filter
105+
106+
To clear a filter, set its value to `null` or an empty string `""`:
107+
108+
```json
109+
PUT /test-index/settings
110+
{
111+
"persistent": {
112+
"index.routing.allocation.exclude._host_ip": null
113+
}
114+
}
115+
```
116+
{% include copy-curl.html %}
117+
118+
## Example response
119+
120+
```json
121+
{
122+
"acknowledged": true
123+
}
124+
```
125+
126+

_api-reference/index-apis/shrink-index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ redirect_from:
1111
**Introduced 1.0**
1212
{: .label .label-purple }
1313

14-
The shrink index API operation moves all of your data in an existing read-only index into a new index with fewer primary shards.
14+
The shrink index API operation moves all of your data in an existing read-only index into a new index with fewer primary shards. This operation requires that a copy of each shard, either primary or replica, is located on the same node. You can use [shard allocation filtering]({{site.url}}{{site.baseurl}}/api-reference/index-apis/shard-allocation/) to move shards to the same node.
1515

1616
To make the index read-only, set the [dynamic index-level index setting]({{site.url}}{{site.baseurl}}/install-and-configure/configuring-opensearch/index-settings/#dynamic-index-level-index-settings) `index.blocks.write` to `true`.
1717
{: .note}

0 commit comments

Comments
 (0)