What you read in this article:
What is NRT in Elasticsearch?
Elasticsearch is a kind of search engine. This platform is famous for its NRT or Near Real time. Near Real time phrase is also given to this platform because of the short time between documenting an index and being searchable.
What does Cluster mean in Elasticsearch?
“Cluster” includes a group of Nodes or servers that store all of your data. A cluster helps you to index and search on all nodes. Cluster name should be a special name because for placing a node in a cluster, we need to name that particular cluster. It is very important to choose why this name is chosen and what its values are. The default name for a Cluster is usually Elasticsearch.
What does the term Node mean in Elasticsearch?
A node contains one server which is in the Cluster. This node is involved both in searching and indexing a cluster and stores our data. Choosing a name for a Node is important, just like clustering. When a Node is creating, the default name or UUID is chosen randomly; and you can change it later as you like. For the site administrator, the name Node is very valuable because, for supervision of a particular server, it must have its name. The Node name is dependent on the Cluster name. Because of that, if we do not change the default name of a Cluster, which is Elasticsearch, the Node will be shown in the very same name.
Learn about Index in Elasticsearch
An index has a group of documents that have the same features that we mentioned in (Elasticsearch Part 2). All indexes should be written in small letters and you can keep the index as much as you want, on a cluster. All delete, update, indexing, and search operations can be performed on just one index.
Type in Elasticsearch
A Type is used for the ordination of an Index. For example, by using Document Type in an Index, you can create different categories for passwords or blog posts.
What is Document in Elasticsearch?
A document is a proof that has some amounts of information that can be indexed. With Index / Type, you can create and maintain Documents in Index as much as you want. These documents have JSON format (a term in web programming used to send data from a web server to a web page).
Term Shards & Replicas in Elasticsearch
An index can have so much information, but this amount is not infinite and you can encounter a fill node. For solving this problem, you can use the Index split feature. Each Index can be shared into smaller sections, each of which is called a Shard. Each of these shared works independently of each other so that each part of an Index can be stored on the desired part of the Node located on a Cluster. This feature is important because of 2 reasons.
1- Helps you to share your information in horizontal form.
2- By using this feature, you can run several operations simultaneously on each of the Shards. This feature is so useful when the Shards are on several different Nodes. Elasticsearch manages how Shards are distributed and Document is linked to searches performed. In the cyber world, data can be lost at any time. To prevent this, it is best to have a back of your data. Elasticsearch helps you to make as many copies of your Shards as you need. These versions are called Replica shards or Replicas.
Using these alternatives has two benefits. First, if a Shard crashes, Node will give you a backup. This backup is never stored on the same Node as the main Shard. The second advantage is the increase in the search domain between different Shards and the main and backup Shards. A Shard can be with or without a backup. The original Shard is also called the Shard original.
Cluster Health Test in Elasticsearch
Cluster health testing on Elasticsearch is done to confirm that it is working properly. For checking cluster health, an API can be used:
In this case, a request is sent and a response comes back from the cluster. To determine the health status of the cluster, it is better to specify the color of this issue. The green status indicates the correct operation of the cluster. If the status color is yellow, it means that all big and small data are available, but some replicas have not been created yet. If part of the data is not available and the cluster is functioning normally until launch, the status color will be red.
If we want to get all the nodes in a cluster, we can use the following test.
In this case, also a request is sent and a response comes back from the cluster.
Build an Index in the Cluster
For creating a clustered index in Elasticsearch, use the following command to create an index called customer.
Then, by using the following command, we can see a list, which has all the items in it.
In the two examples above, you can see that in the PUT /customer?pretty command, adding Pretty causes Json to respond to your request in a beautiful way. In addition to that, our response from GET / _cat / indices?V shows that this Index contains 5 Primary Shard files, as well as a replica of it (according to the Pri and Rep columns). Docs.Count also shows that the existing Index does not contain any Document files.
As you can see, the status color in the table is yellow. The reason for this is not knowing the Replica inside the Node in the Index. By moving a copy from Replica to another Node, the Status color will become green.
Index andQuery a Document
To index a customer document, first, we set the id value to 1, and then with using the following command we do this.
“name”: “John Doe”
Click here to read more articles on DevOps.
Then, using api and id, we get the same document that we indexed through the command below.
The answer to this request is as follows:
Clear an Index in Cluster
To clear an index, we use the following api.
In this example, we deleted an index named customer and as you can see, after deleting the customer, we got a list of available indexes and there was no index named customer.
To view part two: