Elasticsearch Cluster Management

Source: Internet
Author: User

ES can automatically organize nodes of the same cluster name into the cluster by setting "node name" and "Cluster Name", and make many technologies transparent to users.

If the user wants to manage the status of the view cluster, it can be done through some rest APIs.

Other ES document translation reference: Elasticsearch Document Summary

REST API Usage

ES provides a number of comprehensive APIs that can be broadly divided into the following categories:

1 checking the health of clusters, nodes, and indexes

2 managing clusters, nodes, index data, meta data

3 performing crud, creating, reading, updating, deleting, and querying

4 Perform advanced query operations such as paging, sorting, scripting, aggregation, etc.

View cluster status

You can use the Curl command to send rest commands to query the health status of the cluster:

' localhost:9200/_cat/health?v '

LocalHost is the address of the host, 9200 is the port number of listening, ES default listener port number is 9200.

It is important to note that curl installed under Windows may not support single quotes, and if there is an error, please change to double quotation marks, internally escaped with escape character.

The corresponding results obtained:

Epoch      timestamp cluster       status node.total node.data shards pri relo init unassign1394735289 £ º  elasticsearch Green           1         1      0    0    0    0        0

You can see that the name of the cluster is the default "Elasticsearch", the state of the cluster is "green". This color has also been said before:

1 green, healthiest state, representing all shards including backup available

2 yellow, basic shard available, but backup unavailable (or possibly no backup)

3 Red, part of the Shard is available, indicating that the Shard is partially damaged. At this time to execute the query part of the data can still be found, encountered this situation, or quickly solve the better.

The above results can also be seen, there is a node, but there is no Shard, this is because we have no data in ES, once there is no shard.

When using Elasticsearch as the cluster name, unicast is used to query whether other nodes are still running on this computer. If so, a cluster is formed.

(If you use a different name as the cluster name, you may be using multicast!) This in the work, often encounter, we use a cluster name, shards are always engaged, resulting in someone's machine after the offline, their own can not be used)

You can query the list of nodes by using the following command:

' localhost:9200/_cat/nodes?v '

The results are as follows:

' localhost:9200/_cat/nodes?v ' host         IP        heap.percent ram.percent load node.role master namemwubuntu1    127.0.  1.1            8           40.00 D         *      New Goblin
See all the Indexes

The index in ES has two meanings:

1 The index of the verb, which indicates the process of storing the data in ES and providing the search, may be performing a process of creating a search during this period.

2 name index, which is a storage type in ES, similar to a database, contains the Type field internally, and the type contains various documents.

You can view all the indexes by using the following command:

' localhost:9200/_cat/indices?v '

The results are as follows:

' localhost:9200/_cat/indices?v ' Health Index PRI rep docs.count docs.deleted Store.size pri.store.size

Because there is no data in the cluster, the above results contain only the column information.

Create an index

Here is an example of creating an index and querying an index:

curl-xput ' Localhost:9200/customer?pretty ' {  "acknowledged"true}' localhost:9200/_ Cat/indices?v 'Healthindex    PRI rep docs.count docs.deleted Store.size Pri.store.sizeyellow Customer    5   1          0            0       495b           495b

In the above results, the status of the customer index is yellow, because there are 5 primary shards and one backup at this time. However, because it is only a single node, our shards are still running and cannot be modified dynamically. So when other nodes are added to the cluster, the backup node is copied to the other node, and the status becomes green.

Index and search documents

As previously mentioned, there is a concept of type in the index, which is set to the type before the document is indexed.

The following commands are executed:

' Localhost:9200/customer/external/1?pretty ' ' {  "name""John Doe"}' 

After successful execution, you will get the following information:

{  "_index":"Customer",  "_type":"External",  "_id":"1",  "_version":1,  "created":true}

Note that the 2.0 version of ES under the same index, different types, same field names, is not allowed for inconsistent field types.

In the example above, a document was created for us, and the ID is automatically set to 1.

Es no need to explicitly create an index before indexing the document, and if the above command is executed, the index does not exist and the index is automatically created.

Execute the following command query, and the return information is as follows:

Curl-xget'Localhost:9200/customer/external/1?pretty'{  "_index":"Customer",  "_type":"External",  "_id":"1",  "_version":1,  "found":true,"_source": {"name":"John Doe" }}

Two new fields are added here:

1 found describes the request information

2 _source The data at the time of the previous index

Delete Index

You can delete the index by executing the following command:

' Localhost:9200/customer?pretty '

return Result:

{    "acknowledged"true}
Summarize

The summary of the commands involved is as follows:

Curl-xput'Localhost:9200/customer'//CREATE INDEX
//Insert data Curl-xput'LOCALHOST:9200/CUSTOMER/EXTERNAL/1'-D'{ "name":"John Doe"}'Curl'LOCALHOST:9200/CUSTOMER/EXTERNAL/1'//query data Curl-xdelete'Localhost:9200/customer'//delete index
Reference

1 "elasticsearch official documents": https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

Elasticsearch Cluster Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.