日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

探索Elasticsearch集群API

發布時間:2025/3/21 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 探索Elasticsearch集群API 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  Elasticsearch提供了一個非常全面和強大的REST?API,您可以使用與您的集群進行交互。為數不多的可以用API的事情如下:

  • 檢查您的集群、節點和索引健康狀態和統計數據

  • 管理集群、節點和索引數據和元數據

  • 執行CRUD(創建、讀取、更新和刪除)索引和搜索操作

  • 執行高級搜索操作,比如分頁、排序、過濾、腳本、聚合,和許多其他人


1. 可以使用?_cat?API查看elasticsearch的健康狀況,但是啟動時不能以守護進程方式啟動。

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%

健康狀態有三個狀態:

  • ? ? Green:集群一切正常

  • ? ? Yellow:數據可用,副本不可用

  • ? ? Red:部分數據不可用,也可能有部分數據能用。


2. 查看節點列表

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. 創建“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個分片和1個副本(默認值),它包含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,我們可以很快的查詢服務器的狀態,發現服務器的運行問題。





本文轉自 genuinecx 51CTO博客,原文鏈接:http://blog.51cto.com/favccxx/1793005,如需轉載請自行聯系原作者

總結

以上是生活随笔為你收集整理的探索Elasticsearch集群API的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。