【ElasticSearch系列(四)】elasticsearch安装ik分词插件(6.3.0版本)

1、介绍

elasticseach默认所有分词解析器对中文都不友好,开发建议使用Ik分词;

IK Analyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包。从2006年12月推出1.0版开始, IKAnalyzer已经推出了3个大版本。最初,它是以开源项目Luence为应用主体的,结合词典分词和文法分析算法的中文分词组件。新版本的IK Analyzer 3.0则发展为面向Java的公用分词组件,独立于Lucene项目,同时提供了对Lucene的默认优化实现。

2、安装

安装ik分词插件之前,前提是已经安装了es(安装步骤可参考:https://blog.csdn.net/zhanyu1/article/details/88079626),安装的ik版本和es版本也要对应, 版本对应关系详见ik主页:https://github.com/medcl/elasticsearch-analysis-ik

ik主页中有两种安装方式

  • optional 1 - download pre-build package from here: https://github.com/medcl/elasticsearch-analysis-ik/releases

    create plugin folder cd your-es-root/plugins/ && mkdir ik

    unzip plugin to folder your-es-root/plugins/ik

  • optional 2 - use elasticsearch-plugin to install ( supported from version v5.5.1 ):

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.0/elasticsearch-analysis-ik-6.3.0.zip

我们使用第一种,按照上述说明的步骤,直接下载解压即可。

安装后,plugins下,会有一个analysis-ik目录,目录下有jar包和配置文件,然后我们重启es;

接着再安装下head插件,用来测试ik分词的效果,安装步骤可参考:https://blog.csdn.net/zhanyu1/article/details/88083290

3、测试

ik分词有两种ik_smart , ik_max_word,强烈建议用后者ik_max_word,分词结果很多,提高命中率;

创建index索引 put http://localhost:9200/index

创建映射

post  http://localhost:9200/index/fulltext/_mapping  

{
        "properties": {

            "content": {

                "type": "text",

                "analyzer": "ik_max_word",

                "search_analyzer": "ik_max_word"

            }

        }

}

索引几个文档

post  http://localhost:9200/index/fulltext/1

{"content":"美国留给伊拉克的是个烂摊子吗"}

post  http://localhost:9200/index/fulltext/2

{"content":"公安部:各地校车将享最高路权"}

post  http://localhost:9200/index/fulltext/3

{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}

post  http://localhost:9200/index/fulltext/4

{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}

然后我们来搜索测试:

post http://localhost:9200/index/fulltext/_search/

{

    "query" : { "match" : { "content" : "中国嫌犯" }},

    "highlight" : {

        "pre_tags" : ["<tag1>", "<tag2>"],

        "post_tags" : ["</tag1>", "</tag2>"],

        "fields" : {

            "content" : {}

        }

    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

和光同其尘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值