elasticsearch-head是一个界面化的集群操作和管理工具,可以对集群进行傻瓜式操作。你可以通过插件把它集成到ES(首选方式),也可以安装成一个独立webapp。
elasticsearch-head主要有以下方面的操作(官网):
显示集群的拓扑,并且能够执行索引和节点级别操作搜索接口能够查询集群中原始json或表格格式的检索数据能够快速访问并显示集群的状态有一个输入窗口,允许任意调用RESTful API。这个接口包含几个选项,可以组合在一起以产生有趣的结果A. 请求方法(get、put、post、delete),查询json数据,节点和路径
JSON验证器能够重复请求计时器能够使用javascript表达式变换结果收集结果的能力随着时间的推移(使用定时器),或比较的结果能够在一个简单的条形图展示图表转换后的结果 (包括时间序列)注意:如果你不小心,通过此接口,你可能会破坏数据。
elasticsearch-head官网网站:https://github.com/mobz/elasticsearch-head
这里我们只介绍通过插件的方式来安装head,另一种以服务器的方式安装,请参考官网文档。
elasticsearch-head作为插件安装有两种方式:
第一种方式:通过elasticseach自带的plugin命令
(1) 对于Elasticsearch2.x版本:
bin/plugin install mobz/elasticsearch-head
(2) forElasticsearch 1.x:
bin/plugin -install mobz/elasticsearch-head/1.x
(3) Elasticsearch0.9:
bin/plugin -install mobz/elasticsearch-head/0.9
比如我实际环境采用这种方式安装head插件:
bin/plugin install mobz/elasticsearch-head
输出结果:
-> Installing mobz/elasticsearch-head...
Tryinghttps://github.com/mobz/elasticsearch-head/archive/master.zip ...
Downloading .....................DONE
Verifyinghttps://github.com/mobz/elasticsearch-head/archive/master.zip checksums ifavailable ...
NOTE: Unable to verify checksum for downloadedplugin (unable to find .sha1 or .md5 file to verify)
Installed head into /var/lib/elastic/elasticsearch/plugins/head
查看插件的目录:
ls -l elasticsearch-2.3.5/plugins/head
输出结果:
-rw-rw-r-- 1 elastic elastic 104 8月 13 17:15 elasticsearch-head.sublime-project
-rw-rw-r-- 1 elastic elastic 2171 8月 13 17:15Gruntfile.js
-rw-rw-r-- 1 elastic elastic 3482 8月 13 17:15grunt_fileSets.js
-rw-rw-r-- 1 elastic elastic 1082 8月 13 17:15index.html
-rw-rw-r-- 1 elastic elastic 559 8月 13 17:15 LICENCE
-rw-rw-r-- 1 elastic elastic 795 8月 13 17:15 package.json
-rw-rw-r-- 1 elastic elastic 100 8月 13 17:15 plugin-descriptor.properties
-rw-rw-r-- 1 elastic elastic 5146 8月 13 17:15README.textile
drwxrwxr-x 5 elastic elastic 4096 8月 13 17:15_site
drwxrwxr-x 4 elastic elastic 4096 8月 13 17:15src
drwxrwxr-x 4 elastic elastic 4096 8月 13 17:15test
第二种方式:zip包方式安装(针对Elasticsearch服务器无法连接外网)
(1) 通过https://github.com/mobz/elasticsearch-head下载zip包并解压缩
(2) elasticsearch集群安装的路径为/var/lib/elastic/elasticsearch-2.3.5,所以需要建立
建立/var/lib/elastic/elasticsearch-2.3.5/plugins/head目录
(3) 将解压后的elasticsearch-head-master文件夹下的文件拷贝到head目录中
elasticsearch-head插件安装好后,访问elasticsearch界面:
这里我查看新搭建的一个测试环境(生产环境内容太多,不方便展示):
通过查看上图页面,展示了Elasticsearch集群的环境信息,其中包括:
(1) Elasticsearch的连接地址
(2) 集群的节点信息,包括master节点(星号标记)和slave节点
(3) 集群的状态为green
(4) 索引建立
(5) 搜索
(6) 结构化查询
其实内容还有很多,朋友们自己可以点一点,只要掌握了Elasticsearch的基本内容,就可以完全能够熟练操作head插件的各方面功能。
其实通过上图,大家看出了,我们还没有创建用户自己的索引,下面我们简单通过head插件方式来创建索引:
点击“Indices”,弹出页面:
点击“New Index”创建索引,弹出页面:
填写好索引名称后,点击“OK”。
这里大家看到了默认Shards为5,Replicas为1。
大家再查看“Overview”页面,如下:
这时可以查看到我们刚才创建的索引megacorp。你可以点击索引下方的“Info”查看索引的状态和元数据,同样你也可以点击索引下方的“Actions”对索引进行相关的操作:
我们这里再通过后面往索引中插入文档内容,然后演示通过head插件的搜索功能:
curl -XPUT'http://gpmaster:9200/megacorp/employee/1' -d '{
"first_name" :"John",
"last_name" : "Smith",
"age" : 25,
"about" : "Ilove to go rock climbing",
"interests": ["sports", "music" ]
}'
curl -XPUT'http://gpmaster:9200/megacorp/employee/2' -d '{
"first_name" : "Jane",
"last_name" : "Smith",
"age" : 32,
"about" : "Ilike to collect rockalbums",
"interests": ["music" ]
}'
curl -XPUT'http://gpmaster:9200/megacorp/employee/3' -d '{
"first_name" : "Douglas",
"last_name" : "Fir",
"age" : 35,
"about": "Ilike to build cabinets",
"interests": ["forestry" ]
}'
如上我们执行的操作包括:
(1) 为每个员工的文档(document)建立索引,每个文档包含了相应员工的所有信息。
(2) 每个文档的类型为employee。
(3) employee类型归属于索引megacorp。
(4) megacorp索引存储在Elasticsearch集群中。
下面我们通过head插件来执行搜索:
1. 搜索编号为1的员工信息:
2. 复杂查询