Skip to content

Instantly share code, notes, and snippets.

@glenacota
Last active March 3, 2019 21:57
Show Gist options
  • Save glenacota/ae485a2c328834988e5b0ba83dc59db8 to your computer and use it in GitHub Desktop.
Save glenacota/ae485a2c328834988e5b0ba83dc59db8 to your computer and use it in GitHub Desktop.
An exercise to practice with shard allocation strategies in Elasticsearch.
# GOAL: Allocate the shards in a way that satisfies a given set of requirements
# INITIAL SETUP: /
# Download the latest 6.x version of Elasticsearch and Kibana
# Deploy the cluster `eoc-06-cluster`, with three nodes named `node1`, `node2`, and `node3`
# Configure the Zen Discovery module of each node so that they can communicate with each other
# Connect a Kibana instance to `node3`
# Start the cluster
# Create the index `hamlet-1` with two primary shards and one replica
# Add some documents to `hamlet-1` by running the following _bulk command
PUT hamlet-1/_doc/_bulk
{"index":{"_index":"hamlet-1","_id":0}}
{"line_number":"1","speaker":"BERNARDO","text_entry":"Whos there?"}
{"index":{"_index":"hamlet-1","_id":1}}
{"line_number":"2","speaker":"FRANCISCO","text_entry":"Nay, answer me: stand, and unfold yourself."}
{"index":{"_index":"hamlet-1","_id":2}}
{"line_number":"3","speaker":"BERNARDO","text_entry":"Long live the king!"}
{"index":{"_index":"hamlet-1","_id":3}}
{"line_number":"4","speaker":"FRANCISCO","text_entry":"Bernardo?"}
{"index":{"_index":"hamlet-1","_id":4}}
{"line_number":"5","speaker":"BERNARDO","text_entry":"He."}
# Create the index `hamlet-2` with two primary shard and one replica
# Add some documents to `hamlet-2` by running the following _bulk command
PUT hamlet-2/_doc/_bulk
{"index":{"_index":"hamlet-2","_id":5}}
{"line_number":"6","speaker":"FRANCISCO","text_entry":"You come most carefully upon your hour."}
{"index":{"_index":"hamlet-2","_id":6}}
{"line_number":"7","speaker":"BERNARDO","text_entry":"Tis now struck twelve; get thee to bed, Francisco."}
{"index":{"_index":"hamlet-2","_id":7}}
{"line_number":"8","speaker":"FRANCISCO","text_entry":"For this relief much thanks: tis bitter cold,"}
{"index":{"_index":"hamlet-2","_id":8}}
{"line_number":"9","speaker":"FRANCISCO","text_entry":"And I am sick at heart."}
{"index":{"_index":"hamlet-2","_id":9}}
{"line_number":"10","speaker":"BERNARDO","text_entry":"Have you had quiet guard?"}
# Check that both indices `hamlet-1` and `hamlet-2` have a green status
# Configure `hamlet-1` to allocate both primary shards to `node2`, using the node name
# Verify the success of the last action by using the _cat API
# Configure `hamlet-2` so that no primary shard is allocated to `node3`
# Verify the success of the last action by using the _cat API
# Remove any allocation filter setting associated with `hamlet-1` and `hamlet-2`
# Let's assume that we have deployed the `eoc-06-cluster` cluster across two availability zones, named `earth` and `mars`. Add the attribute `AZ` to the nodes configuration, and set its value to "earth" for `node1` and `node2`, and to "mars" for `node3`
# Restart the cluster
# Configure the cluster to force shard allocation awareness based on the two availability zones, and persist such configuration across cluster restarts
# Verify the success of the last action by using the _cat API
# Configure the cluster to reflect a hot/warm architecture, with `node1` as the only hot node
# Configure the `hamlet-1` index to allocate its shards only to warm nodes
# Verify the success of the last action by using the _cat API
# Remove the hot/warm shard filtering configuration from the `hamlet-1` configuration
# Let's assume that the nodes have either a "large" or "small" local storage. Add the attribute `storage` to the nodes configuration, and set its value so that `node2` is the only with a "small" storage
# Configure the `hamlet-2` index to allocate its shards only to nodes with a large storage size
# Verify the success of the last action by using the _cat API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment