一、安装
ealsticsearch只是后端提供各种api,那么怎么直观的使用它呢?elasticsearch-head将是一款专门针对于elasticsearch的客户端工具
elasticsearch-head配置包,下载地址:https://github.com/mobz/elasticsearch-head
elasticsearch-head是一个基于node.js的前端工程
- nodejs安装
# wget https://nodejs.org/dist/v10.9.0/node-v10.9.0-linux-x64.tar.xz    // 下载
# tar xf  node-v10.9.0-linux-x64.tar.xz       // 解压
# cd node-v10.9.0-linux-x64/                  // 进入解压目录
# ./bin/node -v                               // 执行node命令 查看版本
v10.9.0
 解压文件的 bin 目录底下包含了 node、npm 等命令,我们可以使用 ln 命令来设置软连接: ln -s /usr/software/nodejs/bin/npm   /usr/local/bin/ 
ln -s /usr/software/nodejs/bin/node   /usr/local/bin/
 
2.phantomjs安装配置
Wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar –jxvf  phantomjs-2.1.1-linux-x86_64.tar.bz2
  vim /etc/profile
export PATH=$PATH:/usr/local/phantomjs-2.1.1-linux-x86_64/bin 
 #注意环境变量$Path移动在最前面
source /etc/profile
3.elasticsearch-head安装
•   git clone git://github.com/mobz/elasticsearch-head.git
•   cd elasticsearch-head
•   npm install -g cnpm --registry=https://registry.npm.taobao.org
(直接安装 会存在phantomjs克隆不下来导致安装进行不下去,出现以下错误,所以需要先安装phantomjs) 

•   npm run start
•   open http://localhost:9100/
- 
elasticsearch-head发现主机 并连接
 elasticsearch.yml配置文件修改:
 http.cors.enabled: true
http.cors.allow-origin: "*"
 二、使用
 仔细观察,我们会发现客户端默认连接的是我们elasticsearch的默认路径。而此时elasticsearch服务未启动,所以集群健康值是未连接
 集群健康值的几种状态如下:
 绿颜色,最健康的状态,代表所有的分片包括备份都可用
 黄颜色,基本的分片可用,但是备份不可用(也可能是没有备份)
 红颜色,部分的分片可用,表明分片有一部分损坏。此时执行查询部分数据仍然可以查到,遇到这种情况,还是赶快解决比较好
 灰色,未连接到elasticsearch服务
 1.集群概览(关于集群配置 详见后续文章)
 此时,我们启动elasticsearch服务,重新刷新浏览器,发现集群健康值变成了绿色,代表集群很健康,如下:
  
 五星代表是主节点,圆代表是从节点,我们这个测试环境有两个索引products和artices,索引详细信息可点击某个索引,查看该索引的所有信息,包括mappings、setting等等
  
 2.索引
  
 点击新建索引,可以新建索引
  
 输入索引名称,分片数,副本数量,可以新建成功,成功会有如下提示:
  
 3.数据浏览
  
 可查看所有索引、类型、字段信息
 4.基本查询
 可根据查询条件,搜索过滤找到自己需要的索引数据
  
 5.复合查询
 在这个页签,可以使用json进行复杂的查询,也可发送put请求新增及跟新索引,使用delete请求删除索引等等。如图所示:
  
 更多介绍,请查看https://github.com/mobz/elasticsearch-head