Elasticsearch自定义分词器

版权声明:https://blog.csdn.net/qq_38270106 https://blog.csdn.net/qq_38270106/article/details/84575785

什么是分词器

因为Elasticsearch中默认的标准分词器分词器对中文分词不是很友好,会将中文词语拆分成一个一个中文的汉字。因此引入中文分词器-es-ik插件

演示传统分词器

http://192.168.33.129:9200/_analyze

{
  "analyzer": "standard",
  "text": "奥迪a4l"

如下图所示 

 请求结果

 

下载地址: https://github.com/medcl/elasticsearch-analysis-ik/releases 

或者下载插件:https://download.csdn.net/download/qq_38270106/10811833

注意: es-ik分词插件版本一定要和es安装的版本对应

第一步:下载es的IK插件(资料中有)命名改为ik插件

第二步: 上传到/usr/local/elasticsearch-6.4.3/plugins

第三步: 重启elasticsearch即可

 http://192.168.33.129:9200/_analyze

{
  "analyzer": "ik_smart",
  "text": "奥迪a4l"

 

 

自定义扩展字典

在/usr/local/elasticsearch-6.4.3/plugins/ik/config目录下

cd /usr/local/elasticsearch-6.4.3/plugins/ik/config

mkdir custom

vi custom/new_word.dic

加入以下内容 

老铁
王者荣耀
洪荒之力
共有产权房
一带一路

配置分词器路径 

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

 重启elastiasearch

查看效果 

猜你喜欢

转载自blog.csdn.net/qq_38270106/article/details/84575785