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"}}'