It happens that you need to archive data with the ability to quickly search through the data.

First, you need to decide on the format of the indexes themselves. Since the system can accommodate a lot of data, there will only be one cluster for now. To do this, let’s put the data class in the names - prod, sandbox and test.

These data classes can be very easily divided into patterns to work with templates, life cycles and other things. It’s convenient for me to declare all this as a prefix to the index name.

First, let’s make global settings

curl -k -XPUT -u elastic \
    -H "Content-Type: application/json" \
    'https://localhost:9200/_template/default' -d '{
  "index_patterns": ["*"],
  "settings": {
    "index": {
      "codec": "best_compression"
    }
  }
 }'
curl -k -XPUT -u elastic \
    -H "Content-Type: application/json" \
    'https://localhost:9200/_all/_settings' -d '{
  "index.number_of_replicas": "1",
  "index.number_of_shards": "2"
}'

Next we make individual settings

curl -k -XPUT -u elastic \
    -H "Content-Type: application/json" \
    'https://localhost:9200/_template/svc-sandbox' -d '{
  "index_patterns": ["sandbox-*"],
  "settings": {
    "index": {
      "number_of_replicas": "0",
      "number_of_shards": "2"
    }
  }
}'
curl -k -XPUT -u elastic \
    -H "Content-Type: application/json" \
    'https://localhost:9200/_template/svc-prod' -d '{
  "index_patterns": ["prod-*"],
  "settings": {
    "index": {
      "number_of_replicas": "1",
      "number_of_shards": "4"
    }
  }
}'
curl -k -XPUT -u elastic \
    -H "Content-Type: application/json" \
    'https://localhost:9200/_template/svc-test' -d '{
  "index_patterns": ["test-*"],
  "settings": {
    "index": {
      "number_of_replicas": "0",
      "number_of_shards": "1"
    }
  }
}'