Elasticsearch 6 shard/replica settings for single-node cluster

Elasticsearch 6 shard/replica settings for single-node cluster

I have trouble finding this every time I need so I figured out I'd make a post out of it.

Single-node Elasticsearch clusters make sense for non-critical data when money has to be saved, or testing/dev.

By default, ES will create multiple shards for each index, with at least one replica. However, on one node the shards will never get replicated, so the cluster health will always be yellow.

To fix that, you need to create a template that will match all futures indexes and set those settings. Ideally you'll want to do that before indexing anything.

In prior versions of Elasticsearch, this was a setting in elasticsearch.yml, but this is not the case anymore.

Here is the template:

curl -X PUT http://localhost:9200/_template/default \
-H 'Content-Type: application/json' \
-d \
'{
  "index_patterns": ["*"],
  "order": -1,
  "settings": {
    "number_of_shards": "1",
    "number_of_replicas": "0"
  }
}'

Single line version:

curl -X PUT http://localhost:9200/_template/default -H 'Content-Type: application/json' -d '{"index_patterns": ["*"],"order": -1,"settings": {"number_of_shards": "1","number_of_replicas": "0"}}'
Stanislas
Author
Stanislas
I like building things with code and computers

Comments

2Atom feed
Markdown supported
  1. Anonymous

    Thanks Brother. Very helpful.

  2. gawa

    The need to use templates instead of index settings in elasticsearch.yml came with elasticsearch 5.

    To quote the doc :

    In previous versions Elasticsearch allowed to specify index level setting as defaults on the node level, inside the elasticsearch.yaml file or even via command-line parameters. From Elasticsearch 5.0 on only selected settings like for instance index.codec can be set on the node level. All other settings must be set on each individual index. To set default values on every index, index templates should be used instead.