一、安装jdk
二、安装ElasticSearch
1.ElasticSearch下载地址:
2: 配置ElasticSearch
3:启动ElasticSearch
4: 安装ElasticSearch服务
三、安装elasticsearch-head
3.1 HEAD简介
3.2 安装HEAD
四、安装集成Ikanalyzer分词器
4.1 什么是分词
4.2 获取 ES-IKAnalyzer插件
4.3 安装插件
4.4 扩展词库
4.5测试 IK
一、安装jdk
ElasticSearch是基于lucence开发的,也就是运行需要java jdk支持。所以要先安装JAVA环境。
由于ElasticSearch 5.x 往后依赖于JDK 1.8的,所以现在我们下载JDK 1.8或者更高版本。
下载JDK1.8,下载完成后安装。
二、安装ElasticSearch
1.ElasticSearch下载地址:
https://www.elastic.co/downloads/elasticsearch
2: 配置ElasticSearch
config目录下:
- jvm.options ===> 配置JVM
- elasticsearch ===> 配置ElasticSearch 信息
例如: elasticsearch.yaml 修改端口:
http.port: 92003
3:启动ElasticSearch
\bin目录下 command 执行 : elasticsearch.bat
访问以下地址 : http://localhost:9200/ 表示访成功:
4: 安装ElasticSearch服务
window下提供以下GUI管理程序 可在bin目录下找到:
- elasticsearch-service-mgr.exe
- elasticsearch-service-x64.exe
elasticsearch-service.bat 是提供安装服务相关功能(本质上是一系列BAT的综合体)
# 安装
bin>elasticsearch-service.bat install
# 卸载
bin>elasticsearch-service.bat remove
# 开始
bin>elasticsearch-service.bat start
#停止
bin>elasticsearch-service.bat stop
# gui管理
bin>elasticsearch-service.bat manager
三、安装elasticsearch-head
3.1 HEAD简介
ElasticSearch-head是一个H5编写的ElasticSearch集群操作和管理工具,可以对集群进行傻瓜式操作。
- 显示集群的拓扑,并且能够执行索引和节点级别操作
- 搜索接口能够查询集群中原始json或表格格式的检索数据
- 能够快速访问并显示集群的状态
- 有一个输入窗口,允许任意调用RESTful API。这个接口包含几个选项,可以组合在一起以产生有趣的结果;
- 5.0版本之前可以通过plugin名安装,5.0之后可以独立运行。
3.2 安装HEAD
安装grunt(安装head前必须安装,已久安装请忽略)
grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.x里之后的head插件就是通过grunt启动的。因此需要安装grunt.
npm install -g grunt-cli
查看版本号 grunt -version
如果下载慢 请使用淘宝镜像: npm config set registry https://registry.npm.taobao.org
# 下载
git clone git://github.com/mobz/elasticsearch-head.git
# 进入到head目录
cd elasticsearch-head
#安装 head
npm install
# 启动head
npm run start
# 浏览器访问地址:
http://localhost:9100/
ElasticSearch配置Head: 在ElasticSearch.yaml中配置
# 增加新的参数,这样head插件可以访问es http.cors.enabled: true http.cors.allow-origin: "*"
# 浏览器访问地址:
http://localhost:9100/
四、安装集成Ikanalyzer分词器
4.1 什么是分词
全文检索就是对一篇文章进行索引,可以根据关键字搜索,类似于mysql里的like语句。
全文索引就是把内容根据词的意义进行分词,然后分别创建索引,例如”你们的激情是因为什么事情来的” 可能会被分词成:“你们“,”激情“,“什么事情“,”来“ 等token,这样当你搜索“你们” 或者 “激情” 都会把这句搜出来.
4.2 获取 ES-IKAnalyzer插件
https://github.com/medcl/elasticsearch-analysis-ik/releases
注意: IK的版本必须与ElasticSearch 一致
4.3 安装插件
将 ik 的压缩包解压到 ES安装目录的plugins/目录下(最好把解出的程序文件 放到新建立的目录下: ),然后重启ES。
4.4 扩展词库
扩展词典可以修改配置文件 config/IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict"></entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
4.5测试 IK
下列工具使用 POSTMAN 发送请求:
创建索引:
http://127.0.0.1:9200/iktest
创建映射(处理规则): http://127.0.0.1:9200/iktest/_mapping
#请求体:
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
}
}
}
测试分词: http://127.0.0.1:9200/_analyze
#请求体
{
"analyzer":"ik_smart",
"text":"天团S.H.E昨在两厅院艺文广场举办17万人露天音乐会,3人献唱多首经典好歌,让现场粉丝听得如痴如醉"
}
测试结果:
{
"tokens": [
{
"token": "天",
"start_offset": 0,
"end_offset": 1,
"type": "CN_CHAR",
"position": 0
},
{
"token": "团",
"start_offset": 1,
"end_offset": 2,
"type": "CN_CHAR",
"position": 1
},
{
"token": "s.h.e",
"start_offset": 2,
"end_offset": 7,
"type": "LETTER",
"position": 2
},
{
"token": "昨在",
"start_offset": 7,
"end_offset": 9,
"type": "CN_WORD",
"position": 3
},
{
"token": "两厅",
"start_offset": 9,
"end_offset": 11,
"type": "CN_WORD",
"position": 4
},
{
"token": "院",
"start_offset": 11,
"end_offset": 12,
"type": "CN_CHAR",
"position": 5
},
{
"token": "艺文",
"start_offset": 12,
"end_offset": 14,
"type": "CN_WORD",
"position": 6
},
{
"token": "广场",
"start_offset": 14,
"end_offset": 16,
"type": "CN_WORD",
"position": 7
},
{
"token": "举办",
"start_offset": 16,
"end_offset": 18,
"type": "CN_WORD",
"position": 8
},
{
"token": "17",
"start_offset": 18,
"end_offset": 20,
"type": "ARABIC",
"position": 9
},
{
"token": "万人",
"start_offset": 20,
"end_offset": 22,
"type": "CN_WORD",
"position": 10
},
{
"token": "露天",
"start_offset": 22,
"end_offset": 24,
"type": "CN_WORD",
"position": 11
},
{
"token": "音乐会",
"start_offset": 24,
"end_offset": 27,
"type": "CN_WORD",
"position": 12
},
{
"token": "3人",
"start_offset": 28,
"end_offset": 30,
"type": "TYPE_CQUAN",
"position": 13
},
{
"token": "献",
"start_offset": 30,
"end_offset": 31,
"type": "CN_CHAR",
"position": 14
},
{
"token": "唱",
"start_offset": 31,
"end_offset": 32,
"type": "CN_CHAR",
"position": 15
},
{
"token": "多首",
"start_offset": 32,
"end_offset": 34,
"type": "CN_WORD",
"position": 16
},
{
"token": "经典",
"start_offset": 34,
"end_offset": 36,
"type": "CN_WORD",
"position": 17
},
{
"token": "好歌",
"start_offset": 36,
"end_offset": 38,
"type": "CN_WORD",
"position": 18
},
{
"token": "让",
"start_offset": 39,
"end_offset": 40,
"type": "CN_CHAR",
"position": 19
},
{
"token": "现场",
"start_offset": 40,
"end_offset": 42,
"type": "CN_WORD",
"position": 20
},
{
"token": "粉丝",
"start_offset": 42,
"end_offset": 44,
"type": "CN_WORD",
"position": 21
},
{
"token": "听得",
"start_offset": 44,
"end_offset": 46,
"type": "CN_WORD",
"position": 22
},
{
"token": "如痴如醉",
"start_offset": 46,
"end_offset": 50,
"type": "CN_WORD",
"position": 23
}
]
}