elasticSearch使用Ik分词,Kibana查询Ik分词

准备工作

    下载安装elasticsearch,本文案例使用的是elasticsearch-6.2.4版本
修改elasticsearch-6.2.4config目录下elasticsearch.yml
    下载ik分词器(注意要与上面es的版本兼容)
将ik分词器放在elasticsearch-6.2.4plugins目录下

修改config目录下IKAnalyzer.cfg.xml配置ik分词

<?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">custom/mydict.dic;</entry>
	 <!--用户可以在这里配置自己的扩展停止词字典-->
	<entry key="ext_stopwords"></entry>
	<!--用户可以在这里配置远程扩展字典 -->
	<!-- <entry key="remote_ext_dict">words_location</entry> -->
	<!--用户可以在这里配置远程扩展停止词字典-->
	<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

新建custom文件夹,并在目录内新建mydict.dic文件。mydict.dic为自己的拓展词典

    下载安装kibana(注意要与上面es的版本兼容)
修改kibana-6.2.4-windows-x86_64config目录下kibana.yml
# 大约在26行
elasticsearch.url: "http://localhost:9200"

运行服务

  1. 在elasticsearch-6.2.4in目录下运行elasticsearch.bat。浏览器访问http://localhost:9200/
  2. 在kibana-6.2.4-windows-x86_64in目录下运行kibana.bat。浏览器访问http://localhost:5601/ 点击左边菜单Dev Tools查询分词
GET _analyze
{
  "analyzer": "ik_smart",
  "text":"今天天气很好"
}

分词成功。在mydict.dic自定义分词中加入今天天气很好词组,重启Es服务,再次查询。 可见查询结果已经变成一个词组,自定义分词成功!

文中相关elasticsearch、kibana服务已上传到下载频道,有需要的可以自行下载。其中es服务中包含了IK分词。
经验分享 程序员 微信小程序 职场和发展