一. head插件下载及安装
1.head插件下载
下载安装head插件是为了更直观的看到数据的变化,并可以实现对数据的简单操作。elasticsearch5.0以下版本可以直接在elasticsearch目录下执行对应的命令安装head插件,但是5.0以上不支持直接安装,本篇介绍5.6.9以上head插件的安装步骤。
下载地址:https:///mobz/elasticsearch-head
可解压到任意目录,但要与elasticsearch的安装目录区分开!!!
2.node.js下载并自行安装
因为head是一个Node.js项目。所以,如果没有安装nodejs需要先安装Node.js,以 Node.js v4.4.3 LTS(长期支持版本)版本为例。
- 32位安装包下载地址: https://nodejs.org/dist/v4.4.3/node-v4.4.3-x86.msi
- 64位安装包下载地址: https://nodejs.org/dist/v4.4.3/node-v4.4.3-x64.msi
检测环境变量中是否配置了Node.js,打开命令行输入命令"path"后可查看:
输入命令"node --version"可查看node版本:
3.安装grunt
因为运行head需要借助grunt命令,所以需要安装grunt。进入Node.js目录下,执行命令npm install -g grunt-cli,将grunt安装位全局命令。
进入head主目录执行npm install安装grunt,安装完成后执行grunt -version查看是否安装成功,会显示安装的版本号。
4.配置Head
1). 进入安装目录下的config目录,修改elasticsearch.yml文件,在文件的末尾加入以下代码
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
2)network.host: 192.168.0.1的注释并改为network.host: 0.0.0.0;去掉 http.port 的注释(也就是去掉#)
3). 双击elasticsearch.bat重启es
4). 在下载好的head文件夹内找到Gruntfile.js,在对应的位置加上hostname: ‘*’
5).启动head:命令行进入head文件夹执行执行npm install 安装完成后执行grunt server 或者npm run start 运行head插件,如果不成功重新安装grunt。成功如下:
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
6).浏览器下访问http://localhost:9100/
5.postman导入数据示例
1).创建索引和mapping
--put请求 localhost:9200/local_library索引名
mappings:
{
"mappings":{
"book":{
"properties":{
"book_id":{
"type":"long",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"book_code":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"book_name":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"book_price":{
"type":"integer",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"book_author":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"book_desc":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
}
如果想试试用postman新增数据,可以添加如下代码
-- post请求 localhost:9200/local_library/book/1 索引/对象/id
{
“book_id”: 1,
“book_code”: “A0001”,
“book_name”: “琴帝”,
“book_price”: 180,
“book_author”: “唐家三少”,
“book_desc”: “最好看的玄幻小说!”
}
结果可在head数据浏览标签下查看,也可以通过postman运行如下代码查看:
-- post请求 localhost:9200/local_library/_search?pretty
{
"query": {
"match": {
"id": "1"
}
}
}
</div>
<link href="" rel="stylesheet">
<div class="more-toolbox">
<div class="left-toolbox">
<ul class="toolbox-list">
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">点赞</span>
<span class="count"></span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打赏开始-->
<!--打赏结束-->
<li class="tool-item tool-more">
<a>
<svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
</a>
<ul class="more-box">
<li class="item"><a class="article-report">文章举报</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="">
<img src="" class="avatar_pic" username="weixin_44008460">
<img src="" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="" data-report-click="{"mod":"popu_379"}" target="_blank">Make it!</a></span>
</div>
<div class="text"><span>发布了25 篇原创文章</span> · <span>获赞 6</span> · <span>访问量 2000</span></div>
</div>
<div class="right-message">
<a href="" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
</a>
<a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a>
</div>
</div>
</div>
-- post请求 localhost:9200/local_library/book/1 索引/对象/id