全文搜索对于中文分词很重要,所以需要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