探索Elasticsearch集群API
Elasticsearch提供了一個(gè)非常全面和強(qiáng)大的REST?API,您可以使用與您的集群進(jìn)行交互。為數(shù)不多的可以用API的事情如下:
-
檢查您的集群、節(jié)點(diǎn)和索引健康狀態(tài)和統(tǒng)計(jì)數(shù)據(jù)
-
管理集群、節(jié)點(diǎn)和索引數(shù)據(jù)和元數(shù)據(jù)
-
執(zhí)行CRUD(創(chuàng)建、讀取、更新和刪除)索引和搜索操作
-
執(zhí)行高級(jí)搜索操作,比如分頁、排序、過濾、腳本、聚合,和許多其他人
1. 可以使用?_cat?API查看elasticsearch的健康狀況,但是啟動(dòng)時(shí)不能以守護(hù)進(jìn)程方式啟動(dòng)。
| 1 2 3 | [root@Server01?~]#??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% |
健康狀態(tài)有三個(gè)狀態(tài):
-
? ? Green:集群一切正常
-
? ? Yellow:數(shù)據(jù)可用,副本不可用
-
? ? Red:部分?jǐn)?shù)據(jù)不可用,也可能有部分?jǐn)?shù)據(jù)能用。
2. 查看節(jié)點(diǎn)列表
| 1 2 3 | [root@Server01?~]#?curl?'127.0.0.1:9200/_cat/nodes?v' host??????ip????????heap.percent?ram.percent?load?node.role?master?name????? 127.0.0.1?127.0.0.1????????????2??????????43?0.00?d?????????*??????Analyzer |
3. 查看索引
| 1 2 | [root@Server01?~]#?curl?'127.0.0.1:9200/_cat/indices?v' health?status?index?pri?rep?docs.count?docs.deleted?store.size?pri.store.size |
沒有任何索引
4. 創(chuàng)建“customer”并查看索引
| 1 2 3 4 5 6 7 | [root@Server01?~]#?curl?-XPUT?'127.0.0.1:9200/customer?pretty' { ??"acknowledged"?:?true } [root@Server01?~]#?curl?'127.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 正如前面所說的副本不可用,有5個(gè)分片和1個(gè)副本(默認(rèn)值),它包含0文件。
5. 添加索引文檔
| 1 2 | [root@Server01?~]#?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. 查詢文檔
| 1 2 3 4 5 6 7 8 9 10 11 | [root@Server01?~]#?curl?-XGET?'127.0.0.1:9200/customer/external/1?pretty' { ??"_index"?:?"customer", ??"_type"?:?"external", ??"_id"?:?"1", ??"_version"?:?1, ??"found"?:?true, ??"_source"?:?{ ????"name"?:?"Little?Boy" ??} } |
6.刪除索引
| 1 2 3 4 5 6 | [root@Server01?~]#?curl?-XDELETE?'127.0.0.1:9200/customer?pretty' { ??"acknowledged"?:?true } [root@Server05?~]#?curl?'127.0.0.1:9200/_cat/indices?v' health?status?index?pri?rep?docs.count?docs.deleted?store.size?pri.store.size |
以上就是Elasticsearch在集群方面常用的API,借助這些API,我們可以很快的查詢服務(wù)器的狀態(tài),發(fā)現(xiàn)服務(wù)器的運(yùn)行問題。
本文轉(zhuǎn)自 genuinecx 51CTO博客,原文鏈接:http://blog.51cto.com/favccxx/1793005,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的探索Elasticsearch集群API的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大容量导入或导出的数据格式 -- Uni
- 下一篇: IP编址的概述