Skip to content

Instantly share code, notes, and snippets.

@cachafla
Last active August 28, 2015 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cachafla/a2efe03cf25153d380d6 to your computer and use it in GitHub Desktop.
Save cachafla/a2efe03cf25153d380d6 to your computer and use it in GitHub Desktop.

ES Concepts

Database:      [DATABASE] -> [TABLE] -> [ROW]
Elasticsearch: [INDEX]    -> [TYPE]  -> [DOCUMENT]

A node is a running instance of Elasticsearch, while a cluster consists of one or more nodes with the same cluster.name that are working together to share their data and workload. As nodes are added to or removed from the cluster, the cluster reorganizes itself to spread the data evenly.

Initial State: Default ES

One node in the cluster is elected to be the master node, which is in charge of managing cluster-wide changes like creating or deleting an index, or adding or removing a node from the cluster. The master node does not need to be involved in document-level changes or searches, which means that having just one master node will not become a bottleneck as traffic grows. Any node can become the master.

An index is a logical namespace that points to one or more physical shards.

A shard is a low-level worker unit that holds just a slice of all the data in the index. A shard is a single instance of Lucene, and is a complete search engine in its own right. Documents are stored and indexed in shards, but applications don’t talk to them directly. Instead, they talk to an index.

A shard can be either a primary shard or a replica shard.

The number of primary shards in an index is fixed at the time that an index is created, but the number of replica shards can be changed at any time. By default, indices are assigned five primary shards.

PUT /blogs
{
   "settings" : {
      "number_of_shards" : 3,
      "number_of_replicas" : 1
   }
}

Single Node, Three Shards: Single Node, Three Shards

If we start a second node, our cluster would look like: Two Nodes with Replicas

If we start a third node, our cluster reorganizes itself to look like: Three Nodes with Replicas

Let’s increase the number of replicas from the default of 1 to 2:

PUT /blogs/_settings
{
   "number_of_replicas" : 2
}

Two Replicas per Shard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment