Elasticsearch provides a very comprehensive and powerful rest API that you can use to interact with your cluster. The few things you can do with the API are as follows:
Check your cluster, node, and index health status and statistics
Managing cluster, node, and index data and metadata
Perform crud (Create, read, update, and delete) indexes and search operations
Perform advanced search operations such as paging, sorting, filtering, scripting, aggregation, and many others
1. You can use _cat
the API to view the health of the Elasticsearch, but cannot start with daemons.
[[email protected] ~]# curl ' 127.0.0.1:9200/_cat/health?v ' epoch timestamp cluster status node.total Node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1463648421 17:00:21 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%
The state of health has three states:
Green: Cluster Everything is OK
Yellow: Data available, copy not available
Red: Some of the data is unavailable, and some data may be available.
2. View the node list
[[email protected] ~]# Curl ' 127.0.0.1:9200/_cat/nodes?v ' host IP heap.percent ram.percent load node.role maste R name 127.0.0.1 127.0.0.1 2 0.00 D * Analyzer
3. View Index
[[email protected] ~]# Curl ' 127.0.0.1:9200/_cat/indices?v ' health status index PRI rep docs.count docs.deleted Store.size Pri.store.size
Does not have any indexes
4. Create a "customer" and view the index
[[email protected] ~]# curl-xput ' 127.0.0.1:9200/customer?pretty ' {"acknowledged": True}[[email protected] ~]# Curl ' 12 7.0.0.1:9200/_cat/indices?v ' health status index PRI rep docs.count docs.deleted store.size pri.store.size Yellow Open Customer 5 1 0 0 260b 260b
Yellow as the previously mentioned copy is not available, there are 5 shards and one copy (the default), which contains 0 files.
5. Add an indexed document
[[email protected] ~]# curl-xput ' 127.0.0.1:9200/customer/external/1?retty '-d ' {"name": "Little Boy"} ' {"_index": " Customer "," _type ":" external "," _id ":" 1 "," _version ": 1," _shards ": {" Total ": 2," successful ": 1," Failed ": 0}," created ": True
6. Querying documents
[Email protected] ~]# curl-xget ' 127.0.0.1:9200/customer/external/1?pretty ' {"_index": "Customer", "_type": "Externa L "," _id ":" 1 "," _version ": 1," found ": true," _source ": {" name ":" Little Boy "}}
6. Deleting an index
[[email protected] ~]# curl-xdelete ' 127.0.0.1:9200/customer?pretty ' {"acknowledged": True}[[email protected] ~]# Curl ' 127.0.0.1:9200/_cat/indices?v ' health status index PRI rep docs.count docs.deleted Store.size pri.store.size
The above is the Elasticsearch in the cluster of common APIs, with these APIs, we can quickly query the status of the server, to find the server running problems.
This article is from the "This person's IT World" blog, be sure to keep this source http://favccxx.blog.51cto.com/2890523/1793005
Explore the Elasticsearch Cluster API