|
| 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 | + |
0 commit comments