Read more

Elasticsearch unassigned replica shards on single node instances

Claus-Theodor Riegg
March 14, 2018Software engineer at makandra GmbH

If you have a single node elasticsearch instance and indices with replicas enabled your cluster state will be yellow. If you have replica shards they should be moved to a different node for high availability purposes. With a single node this can't be accomplished. So you either build a ES cluster or you disable the replicas.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show snapshot

Building a cluster is beyond the scope of this card, but we can have a look how we can disable the replicas.

get the unassigned shards

curl -s -XGET 'localhost:9200/_cat/shards?pretty' | grep UNASSIGNED

If it's a replica (r in the column befor the UNASSIGNED) and you are on a single node elasticsearch you need to disable replicas

get templates with patterns and search which template will be used for the unassigned shard

curl -XGET 'localhost:9200/_template?pretty' \
    | jq 'to_entries[] | { key, index_pattern: .value.index_patterns, number_of_replicas: .value.settings.index.number_of_replicas}'

how to change template configuration

via puppet

You can manage templates with our puppet module. This template will be applied on all indices that start with foobar_. You only need to specify the api_port if your instance runs on a different port than 9200.

    api_port: 9200
      'index_patterns': ['foobar_*']
        'number_of_shards': 1
        'number_of_replicas': 0

Attention: This will replace all existing settings of the template. Make sure to include all default template settings by first checking:

curl -XGET 'localhost:9200/_template/instance_foo?pretty"


Overwrite the template settings:

curl -XPUT 'localhost:9200/_template/footemplate?pretty' \
    -H 'Content-Type: application/json'                  \
    -d '{
            [ "foobar.*(" ], "settings": {
                    { "number_of_shards": 1, "number_of_replicas": 0 }


Now you have fixed the issue for future indices matching the index_pattern of the edited template. But you need to remove the unassigend replica shards already there. Use the index names returned by the first HTTP request and disable replicas for the indices:

curl -XPUT "localhost:9200/$INDEXNAME/_settings?pretty" \
    -H 'Content-Type: application/json'                 \
    -d '{ "index": { "number_of_replicas": 0 } }'

xpack monitoring index template

If the troubeling template is the xpack monitoring template .monitoring-es or any other monitoring template automaticall created (for e.g. .monitoring-kibana) you can't change the settings because xpack will overwrite them. You need to create a separate template which will be applied after the first one: Configuring Indices for Monitoring Show snapshot

Posted by Claus-Theodor Riegg to makandra Operations (2018-03-14 11:31)