ES:Head插件下载安装及数据导入

一. head插件下载及安装

1.head插件下载

下载安装head插件是为了更直观的看到数据的变化,并可以实现对数据的简单操作。elasticsearch5.0以下版本可以直接在elasticsearch目录下执行对应的命令安装head插件,但是5.0以上不支持直接安装,本篇介绍5.6.9以上head插件的安装步骤。

下载地址:https://github.com/mobz/elasticsearch-head

可解压到任意目录,但要与elasticsearch的安装目录区分开!!!

2.node.js下载并自行安装

因为head是一个Node.js项目。所以,如果没有安装nodejs需要先安装Node.js,以 Node.js v4.4.3 LTS(长期支持版本)版本为例。

检测环境变量中是否配置了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;去掉cluster.name node.name 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="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" 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="{&quot;mod&quot;:&quot;popu_824&quot;}"><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="https://blog.csdn.net/weixin_44008460">
                <img src="https://profile.csdnimg.cn/5/6/2/3_weixin_44008460" class="avatar_pic" username="weixin_44008460">
                                        <img src="https://g.csdnimg.cn/static/user-reg-year/2x/1.png" class="user-years">
                                </a></div>
            <div class="middle-message">
                                    <div class="title"><span class="tit"><a href="https://blog.csdn.net/weixin_44008460" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" 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="https://im.csdn.net/im/main.html?userName=weixin_44008460" 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="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                </div>
                        </div>
                </div>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值