How Elasticsearch works inside the cluster

Elasticsearch is used to build highly available and scalable systems. The way of expansion can be to buy better servers (vertical expansion) or buy more servers (horizontal expansion), although vertical expansion can completely enhance the performance of the server, but vertical expansion is limited, we are more inclined to horizontal expansion in practice. Scaling across a traditional database requires a lot more work in the application, but Elasticsearch doesn’t need that at all. Elasticsearch is naturally distributed. This chapter mainly involves clusters, nodes and shards.

An empty cluster

If we expect a single node with no data and no indexes, this is what the cluster looks like

1. A node is an instance of Elasticsearch. A cluster consists of one or more nodes with the same cluster.name that coordinate work and share data and load. When a new node is added or a node is deleted, the cluster perceives and balances the data. 2. The cluster is selected as the master node. He will temporarily manage some changes at the cluster level, such as creating or deleting indexes, adding or removing nodes, etc. The master node does not participate in changing or searching document sections, which means that the master node does not become a bottleneck for the cluster when traffic increases. Any node can be the primary node. A cluster with only one node acts as the master node. 3. We can communicate with any node in the cluster, including the master node. Each node knows that the document exists on that node, and they can forward requests to the corresponding node. The visited nodes are responsible for collecting the data returned by each node and finally reporting the results back to the clientCopy the code

Cluster health

Elasticsearch health statistics cluster health information. The health status of the cluster can be Green,yellow, or Red

 GET /_cluster/health
Copy the code

The result is as follows:

color What color means
green All primary and replicated shards are available
yellow All major shards are available, but not all replicated shards are available
red Not all major shards are available