Elasticsearch精進之路:elasticsearch-head插件使用教程
- 2021 年 3 月 4 日
- 筆記
- elasticsearch
一、elasticsearch-head插件的作用
ealsticsearch是一個分散式、RESTful 風格的搜索和數據分析引擎,所有的數據都是後台服務存儲著,類似於Mysql伺服器,因此如果我們需要直觀的查看數據,就需要使用可視化工具了。elasticsearch-head是Web前端,用於瀏覽和與Elastic Search集群進行交互,可用於集群管理、數據可視化、增刪改查工具Elasticsearch語句可視化等。
二、elasticsearch-head插件的安裝
-
下載elasticsearch-head插件,地址://github.com/mobz/elasticsearch-head
-
進入elasticsearch-head源碼目錄中,執行
npm install
在運行npm install時,可能會存在Head插件phantomjs許可權問題
npm WARN deprecated phantomjs-prebuilt@2.1.16: this package is now deprecated
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
> phantomjs-prebuilt@2.1.16 install E:\JavaDevelopment\elasticsearch\elasticsearch-head-master\node_modules\phantomjs-prebuilt
> node install.js
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip
Saving to C:\Users\ysxx\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip
Receiving...
Error making request.
Error: connect ETIMEDOUT 140.82.114.4:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
Please report this full log at https://github.com/Medium/phantomjs
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ysxx\AppData\Roaming\npm-cache\_logs\2020-12-28T01_28_03_195Z-debug.log解決方案:在npm install命令後加 -g 參數
npm install -g
-
在install成功之後,執行
npm run start
啟動head插件> elasticsearch-head@0.0.0 start E:\JavaDevelopment\elasticsearch\elasticsearch-head-master
> grunt server
>> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100在cmd命令行可以看到 web server 地址,在瀏覽器訪問該地址
//localhost:9100
,如果出現elasticsearch-head插件連不上elasticsearch服務,需要在elasticsearch安裝目錄下的config文件夾,找到elasticsearch.yml文件,添加兩行配置:#表示是否支援跨域,默認為false
http.cors.enabled: true
#當設置允許跨域,默認為*,表示支援所有域名
http.cors.allow-origin: "*"
三、elasticsearch-head插件的使用
-
介面概覽
集群健康值的顏色說明:
顏色 說明 綠色 最健康的狀態,代表所有的分片包括備份都可用 黃色 基本的分片可用,但是備份不可用(也可能是沒有備份) 紅色 部分的分片可用,表明分片有一部分損壞。執行查詢部分數據仍然可以查到,遇到這種情況,還是趕快解決比較好 灰色 未連接到elasticsearch服務 -
數據概覽
-
基本查詢
選擇一個索引,然後再選擇不同的查詢條件,勾選「顯示查詢語句」,點擊搜索,可以看到具體的查詢json和查詢結果,點擊「顯示原始JSON」,可以看到未經格式化的查詢json
-
複合查詢
可以使用json進行複雜的查詢,也可發送put請求新增及跟新索引,使用delete請求刪除索引等等。
使用json進行複雜的查詢,也可發送put請求新增及跟新索引,使用delete請求刪除索引等等。
四、總結
elasticsearch-head插件是較早支援Elasticsearch的可視化客戶端工具之一,目前功能還是能夠使用,介面美感有些不足,在elasticsearch-head插件的GitHub上發布版本的時間(2018年4月)來看,應該屬於功能基本停更的狀態,這也是其使用上的不足之處吧。
elasticsearch-head插件可以對數據進行增刪改查操作,故生產環境盡量不要使用,如果要使用,最少要限制IP地址。