elasticsearch 安装ik中文分词

全文搜索对于中文分词很重要,所以需要ik插件分词支持中文分词
英文使用空格很容易分词,中文需要根据词意进行分词,需要【字典】支持

插件项目:https://github.com/medcl/elasticsearch-analysis-ik

未安装前【分词测试】
postman

post   http://localhost:9200/_analyze
{
    "text":"活动在广东省汕头市澄海区溪南镇举行吗"
    ,"analyzer":"standard"
}
//或者直接
{
    "text":"活动在广东省汕头市澄海区溪南镇举行吗"
}
//测试英文
{
    "text":"I am a good man"
}

安装方法,任意一种:
1、下载 zip 包后,【直接】解压到elasticsearch-6.2.1\plugins\目录下,最后路径类似:elasticsearch-6.2.1\plugins\elasticsearch\plugin-descriptor.properties
zip 包地址:https://github.com/medcl/elasticsearch-analysis-ik/releases

2、es >v5.5.1 (看es安装目录,elasticsearch-6.2.1\bin\elasticsearch-plugin.bat 有没有)

//命令提示符, 下载安装,可能比较慢

C:\Users\test>D:\java\elasticsearch-6.2.1\bin\elasticsearch-plugin.bat install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.1/elasticsearch-analysis-ik-6.2.1.zip

重启es

查看插件是否安装

get  http://localhost:9200/_cat/plugins
//显示,表示安装
jbLBIzO analysis-ik 6.2.1 

安装ik分词插件后,【分词测试】

post   http://localhost:9200/_analyze
{
    "text":"活动在广东省汕头市澄海区溪南镇举行吗"
    ,"analyzer":"ik_max_word"
}

【注意analyzer的名称】(在源码的org/elasticsearch/plugin/analysis/ik/AnalysisIkPlugin.java#getAnalyzers注册的map名字)

public Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> getAnalyzers() {
        Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> extra = new HashMap<>();

        extra.put("ik_smart", IkAnalyzerProvider::getIkSmartAnalyzerProvider);
        extra.put("ik_max_word", IkAnalyzerProvider::getIkAnalyzerProvider);

        return extra;
    }

Elasticsearch analyzers文档
https://www.elastic.co/guide/en/elasticsearch/reference/5.5/analysis-analyzers.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值