Replicas and shard allocation awareness in the Wazuh indexer
Wazuh indices default to three shards and zero replicas. How to add replicas, spread copies across awareness zones and verify it in the OpenSearch 2.19 API.
A fresh Wazuh indexer 4.14 installation creates indices with three primary shards and no replicas, so after losing one node only an incomplete index is available. I describe how to change the replica count, how to set allocation awareness or forced awareness for nodes in different zones, and how to verify it with _cat/shards, _cluster/allocation/explain and _cluster/health.
Wazuh indexer 4.14 is based on OpenSearch 2.19: the buildSrc/version.properties file in the wazuh-indexer repository gives 2.19.3 in tag v4.14.0 and 2.19.6 in v4.14.10. The API parameters come from the OpenSearch 2.19 documentation, and the paths and files from the Wazuh 4.14 documentation.
What the defaults are
The Wazuh documentation states that the default installation creates every index with three primary shards and no replicas. The wazuh-template.json template from tag v4.14.11 confirms this with settings for the wazuh-alerts-4.x-* and wazuh-archives-4.x-* indices:
{
"order": 0,
"index_patterns": ["wazuh-alerts-4.x-*", "wazuh-archives-4.x-*"],
"settings": {
"index.refresh_interval": "5s",
"index.number_of_shards": "3",
"index.number_of_replicas": "0",
"index.auto_expand_replicas": "0-1"
}
}
The fragment shows four of the template settings. Next to number_of_replicas: 0 stands auto_expand_replicas: 0-1. The Wazuh documentation does not describe how these two settings interact, and its custom template example keeps both values unchanged. After changing the replica count, check the result in _cat/shards instead of assuming the value from the request applies.
The number of shards and replicas is set per index when it is created. Replicas can later be changed dynamically, shards cannot be changed without reindexing. Wazuh gives the rule that the number of shards should equal the number of nodes: three nodes mean three shards, one node means one shard.
How many replicas to choose
The documentation describes three variants for a cluster with three nodes and three shards.
| Replicas | Layout | Failure effect |
|---|---|---|
| 0 | each node has one shard | after losing a node, an incomplete index of two shards is available |
| 1 | each node has one shard and one replica | after losing a node, the full index is still available |
| 2 | each node has the whole index: one shard and two replicas | the cluster works after losing two nodes, storage demand grows |
The replica count depends on available storage, because every replica is an additional full copy. The retention policy that limits this cost is described in the post OpenSearch retention. The role split and health checks of a multi-node cluster are covered by Wazuh cluster: configuration and health checks.
Changing replicas in existing indices
The Wazuh documentation shows a dynamic change of the replica count through _settings on wazuh-alerts-*. The vendor example sets the value 0 for a single-node cluster:
curl -k -u "<INDEXER_USERNAME>:<INDEXER_PASSWORD>" -XPUT "https://<INDEXER_IP_ADDRESS>:9200/wazuh-alerts-*/_settings" -H 'Content-Type: application/json' -d'
{
"settings": {
"index": {
"number_of_replicas": 0
}
}
}'
The same request with a different number in number_of_replicas adds replicas. The vendor shows only the value 0, so I recommend starting with one index instead of the wildcard pattern and extending the change to the rest only after checking _cat/shards. Added replicas have to be copied, which loads the disk and network of the nodes. Turning replication off during an upgrade is a separate procedure, described in the post Wazuh 4.14 upgrade.
Default replica count for new indices
The change through _settings applies to indices that already exist. New indices matching the template patterns get its values. The Wazuh documentation describes the procedure with a custom template using a shard count change as the example:
- Download the template from the Wazuh repository:
curl https://raw.githubusercontent.com/wazuh/wazuh/v4.14.11/extensions/elasticsearch/7.x/wazuh-template.json -o w-indexer-template.json. - Set
"order": 1in the file and change the chosen settings. Order 1 protects the template from being overwritten by Filebeat, and several templates with equal order give a nondeterministic merge order. - Load the file as the
wazuh-customtemplate. - Check the result through
_template/wazuh-customwithfilter_path.
curl -X PUT "https://<INDEXER_IP_ADDRESS>:9200/_template/wazuh-custom" -H 'Content-Type: application/json' -d @w-indexer-template.json -k -u <INDEXER_USERNAME>:<INDEXER_PASSWORD>
curl "https://<INDEXER_IP_ADDRESS>:9200/_template/wazuh-custom?pretty&filter_path=wazuh-custom.settings" -k -u <INDEXER_USERNAME>:<INDEXER_PASSWORD>
The vendor example changes index.number_of_shards. For replicas the analogous change is index.number_of_replicas in the template file. For an index that already exists, the documentation requires reindexing when you change shards.
Awareness and forced awareness
The Wazuh documentation points out that awareness is most useful when indexer nodes are spread geographically across zones. The configuration starts with a node attribute in /etc/wazuh-indexer/opensearch.yml. Example: four nodes in two zones. Addresses and names are synthetic, like all values in the article.
| Node | Address | Zone |
|---|---|---|
| node-1 | 192.0.2.11 | zoneA |
| node-2 | 192.0.2.12 | zoneA |
| node-3 | 192.0.2.21 | zoneB |
| node-4 | 192.0.2.22 | zoneB |
In opensearch.yml on node-1 and node-2 add:
node.attr.zone: zoneA
On node-3 and node-4:
node.attr.zone: zoneB
Then enable the mechanism in the cluster. OpenSearch applies a cluster setting to all nodes, so you send the request once:
PUT _cluster/settings
{
"persistent": {
"cluster.routing.allocation.awareness.attributes": "zone"
}
}
The vendor recommends persistent settings, because transient ones do not survive a cluster restart. In the OpenSearch documentation the precedence order is: transient, persistent, opensearch.yml, defaults. Multiple attributes are given separated by commas, for example zone,rack.
The difference between the two modes
| Feature | Allocation awareness | Forced awareness |
|---|---|---|
| Principle | replicas go to a different zone than the primary shard | copies of the same shard never land in one zone |
| Extra setting | none | cluster.routing.allocation.awareness.force.zone.values with a list of zones |
| When one zone remains | replicas go to the only available zone | replicas wait, the cluster goes to yellow state |
| When to choose | disks in both zones are less than 50% full | no zone can hold all primary shards and replicas |
With less than 50% fill, each zone has room for the other zone’s replicas. Forced awareness protects the only surviving zone from filling its disks and blocking the cluster.
You enable forced awareness like this:
PUT _cluster/settings
{
"persistent": {
"cluster.routing.allocation.awareness.attributes": "zone",
"cluster.routing.allocation.awareness.force.zone.values": ["zoneA", "zoneB"]
}
}
Add every additional zone to force.zone.values.
How many copies a zone holds
The OpenSearch 2.19 documentation gives a formula for the maximum number of copies of one shard in a zone: ceil(number_of_shard_copies/number_of_distinct_zones). For an index with one replica and two zones this is ceil(2/2), so one copy per zone, which matches the layout in the node table. For an index with one primary shard and four replicas in three zones the limit is 2 copies per zone. When the first zone has three nodes and the others one each, the last copy stays unassigned for lack of nodes.
The formula counts only the zones available at the moment. After a zone failure, replicas can therefore land in the zone that remains.
Enforcing an even number of copies
The routing.allocation.awareness.balance setting is false by default. When enabled, the total number of shards of an index must be a multiple of the largest number of values of any awareness attribute, otherwise OpenSearch returns a validation error:
PUT _cluster/settings
{
"persistent": {
"cluster": {
"routing.allocation.awareness.balance": "true"
}
}
}
The setting works only when cluster.routing.allocation.awareness.attributes and cluster.routing.allocation.awareness.force.zone.values are set. It covers every operation that creates or changes an index, including an index template. In the vendor example with three nodes in three zones, an index with one replica ends in a validation error, while one shard with two replicas passes.
Verification
Start with cluster health. Status green means all primary shards and their replicas are assigned. Yellow means primary shards are assigned, but some replicas are not. Red means at least one primary shard is unassigned.
GET _cluster/health?level=awareness_attributes
The response contains an awareness_attributes object with a per-zone breakdown: active_shards, initializing_shards, relocating_shards, unassigned_shards and data_nodes. With forced awareness, yellow after a node failure is expected until the nodes of the other zone return.
_cat/shards shows the placement of copies. The h parameter picks the columns, and v=true adds a header:
GET _cat/shards?v=true&h=index,shard,prirep,state,node
The prirep column has p for a primary shard and r for a replica. The documentation shows only the STARTED state. You can filter the output saved to a file locally to list copies that have not started (the state column is the fourth):
awk 'NR>1 && $4 != "STARTED"' shards.txt
The second filter compares the zones of copies of the same shard. The file zones.txt holds node zone pairs from the table above. Each line of the output is a violation of the zone separation rule (it checks only copies in the STARTED state):
awk 'NR==FNR{z[$1]=$2; next} FNR>1 && $4=="STARTED"{k=$1" "$2; zone=z[$5]; if(k in seen && seen[k]==zone) print "SAME ZONE", k, zone; seen[k]=zone}' zones.txt shards.txt
If a replica is unassigned, _cluster/allocation/explain shows the reason. The basic request without options finds an unassigned shard. With a body you point at a specific one:
GET _cluster/allocation/explain
{
"index": "wazuh-alerts-4.x-2026.11.25",
"shard": 1,
"primary": false
}
In the response read node_allocation_decisions, and in it the deciders list with the fields decider, decision and explanation. A same_shard decision with the value NO means a copy of this shard is already on that node. The awareness decision shows whether zone attributes block the assignment. The parameter include_yes_decisions=true adds positive decisions, and include_disk_info=true adds disk information.
You read cluster settings with GET _cluster/settings, and with include_defaults=true the default values too. Cluster health metrics and the shard count with a threshold are monitored by the templates described in Zabbix 7.0 templates for Wazuh. The role of the indexer in the whole architecture is shown in Wazuh architecture.
Rollback
You undo replicas in existing indices with a _settings request with the previous count, for example 0 as in the vendor example. You undo the wazuh-custom template (recommendation) by loading again the file downloaded from tag v4.14.11 with the previous values and order equal to 1. For awareness settings, read the previous value with GET _cluster/settings before the change.
What the documentation does not specify
- Rolling back a cluster setting with the value
nullis not described by any of the source pages, so I do not give that method. - Whether changing
node.attr.zoneinopensearch.ymlrequires a node restart, the documentation does not say. - The recommended replica count for clusters other than the three-node one from the example is not given.
Sources
- https://documentation.wazuh.com/4.14/user-manual/wazuh-indexer/wazuh-indexer-tuning.html
- https://documentation.wazuh.com/4.14/user-manual/wazuh-indexer-cluster/wazuh-indexer-cluster-tuning.html
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.11/extensions/elasticsearch/7.x/wazuh-template.json
- https://raw.githubusercontent.com/wazuh/wazuh-indexer/v4.14.0/buildSrc/version.properties
- https://raw.githubusercontent.com/wazuh/wazuh-indexer/v4.14.10/buildSrc/version.properties
- https://docs.opensearch.org/2.19/tuning-your-cluster/
- https://docs.opensearch.org/2.19/install-and-configure/configuring-opensearch/index/
- https://docs.opensearch.org/2.19/api-reference/cluster-api/cluster-settings/
- https://docs.opensearch.org/2.19/api-reference/cluster-api/cluster-allocation/
- https://docs.opensearch.org/2.19/api-reference/cluster-api/cluster-health/
- https://docs.opensearch.org/2.19/api-reference/cat/cat-shards/