想要给elasticsearch安装一个中文分词插件,网上的资料都有点过时。
现在记录一下从源码安装ik插件的过程。
(注:我用的版本是0.90.2)。
1、下载源码
首先去ik的git网站下站源码,网址:https://github.com/medcl/elasticsearch-analysis-ik
下载完源码后,发现没有对应的jar包。我用mvn package,打了一个jar包。
打包后名称最后是:elasticsearch-analysis-ik-1.2.2.jar
2、文件拷贝。
这一步很简单,将jar包拷贝到ES_HOME/plugin/analysis-ik目录下面。
将config/ik目录下面的东西拷贝纸ES_HOME/config/ik目录下面(我在本机是window,es在linux上面,我是先将文件夹打包成zip包,然后到服务器上解压)。
3、增加配置
编辑elasticsearch.xml,在文件的最后增加下面代码:
index: analysis: analyzer: ik: alias: [ik_analyzer] type: org.elasticsearch.index.analysis.IkAnalyzerProvider ik_max_word: type: ik use_smart: false ik_smart: type: ik use_smart: true
然后重启elasitcsearch。
4、测试分词插件
这个我也不知道为啥使用下面命令不能测试。
curl 'http://localhost:9200/_analyze?analyzer=ik&pretty=true' -d' { "text":"去北京怎么走" } '
但是从es的日志看,插件应该已经是加载了。
我安装ik插件的说明创建了一个索引,然后在索引下面使用上面的查询可以。
curl -XPUT http://localhost:9200/index curl -XPOST http://localhost:9200/index/fulltext/_mapping -d' { "fulltext": { "_all": { "indexAnalyzer": "ik", "searchAnalyzer": "ik", "term_vector": "no", "store": "false" }, "properties": { "content": { "type": "string", "store": "no", "term_vector": "with_positions_offsets", "indexAnalyzer": "ik", "searchAnalyzer": "ik", "include_in_all": "true", "boost": 8 } } } }' //测试命令 curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d' { "text":"去北京怎么走" } '
测试分词效果如下:
{ "text":"去北京怎么走" } ' { "tokens" : [ { "token" : "text", "start_offset" : 4, "end_offset" : 8, "type" : "ENGLISH", "position" : 1 }, { "token" : "去", "start_offset" : 11, "end_offset" : 12, "type" : "CN_CHAR", "position" : 2 }, { "token" : "北京", "start_offset" : 12, "end_offset" : 14, "type" : "CN_WORD", "position" : 3 }, { "token" : "怎么走", "start_offset" : 14, "end_offset" : 17, "type" : "CN_WORD", "position" : 4 } ] }
5、补充
当测试分词“中华人民共和国时",发现竟然没有分词。如下:
curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d' > { > "text":"中华人民共和国" > } > ' { "tokens" : [ { "token" : "text", "start_offset" : 12, "end_offset" : 16, "type" : "ENGLISH", "position" : 1 }, { "token" : "中华人民共和国", "start_offset" : 19, "end_offset" : 26, "type" : "CN_WORD", "position" : 2 } ] }
但这并非我们想要的结果,难道ik这么差,不会分词了?后来经过研究,发现ik有一个smart模式,并且默认是这个模式,在这种模式下,你搜索“中华人民共和国",可能就搜不到仅包含“共和国"的文档。只需使用ik_max_word模式即可修复以上问题,关于分词器,继续探索中....。
curl 'http://localhost:9200/index/_analyze?analyzer=ik_max_word&pretty=true' -d' > { > "text":"中华人民共和国" > } > ' { "tokens" : [ { "token" : "text", "start_offset" : 12, "end_offset" : 16, "type" : "ENGLISH", "position" : 1 }, { "token" : "中华人民共和国", "start_offset" : 19, "end_offset" : 26, "type" : "CN_WORD", "position" : 2 }, { "token" : "中华人民", "start_offset" : 19, "end_offset" : 23, "type" : "CN_WORD", "position" : 3 }, { "token" : "中华", "start_offset" : 19, "end_offset" : 21, "type" : "CN_WORD", "position" : 4 }, { "token" : "华人", "start_offset" : 20, "end_offset" : 22, "type" : "CN_WORD", "position" : 5 }, { "token" : "人民共和国", "start_offset" : 21, "end_offset" : 26, "type" : "CN_WORD", "position" : 6 }, { "token" : "人民", "start_offset" : 21, "end_offset" : 23, "type" : "CN_WORD", "position" : 7 }, { "token" : "共和国", "start_offset" : 23, "end_offset" : 26, "type" : "CN_WORD", "position" : 8 }, { "token" : "共和", "start_offset" : 23, "end_offset" : 25, "type" : "CN_WORD", "position" : 9 }, { "token" : "国", "start_offset" : 25, "end_offset" : 26, "type" : "CN_CHAR", "position" : 10 } ] }
请支持原创:
http://donlianli.iteye.com/blog/1948841
相关推荐
elasticsearch ik插件,github速度比较慢,拉下来分享一下
ElasticSearch安装ik分词插件.txt
elasticsearch-5.3.2,ik 插件已经编译完了。
elasticsearch-ik分词插件.rar,为es的ik分词器插件。
elasticSearch(ES) 最新版ik分词插件7.10 elasticsearch-analysis-ik-7.10.0
ES: elasticsearch-7.9.3-linux-x86_64.tar ik分词器:elasticsearch-analysis-ik-7.9.3.zip 可视化插件:elasticsearch_Head谷歌插件.rar
如果直接使用Elasticsearch的朋友在处理中文... 这是因为使用了Elasticsearch中默认的标准分词器,这个分词器在处理中文的时候会把中文单词切分成一个一个的汉字,因此引入es之中文的分词器插件es-ik就能解决这个问题。
elasticsearch-ik插件
最新版 elasticsearch-analysis-ik-7.13.4.zip最新版 elasticsearch-analysis-ik-7.13.4.zip
elasticsearch-analysis-ik-5.6.8, 中文分词器analysis-ik官方绿色解压版
elasticsearch-analysis-ik-6.3.0.zip elasticsearch-analysis-ik-6.3.0.zip elasticsearch-analysis-ik-6.3.0.zip
elasticsearch-2.2.0,已经安装elasticsearch-sql插件、elasticsearch-head插件、ik分词插件,windows、linux都可以使用
在es的plugins目录下面新建ik文件夹,把该zip压缩包拷贝到ik目录解压,重启esik插件就安装成功了。在es的plugins目录下面新建ik文件夹,把该zip压缩包拷贝到ik目录解压,重启esik插件就安装成功了。
文件说明:本zip包含IKAnalyzer的src及elasticsearch可运行插件plugins两部分。 使用说明:修改src源码后可通过IKAnalzyerDemo、LuceneIndexAndSearchDemo测试分词及检索。将编译后jar包替换plugins中相应jar包即可...
elasticsearch-analysis-ik-6.2.4.zip 插件,elasticsearch-analysis-ik-6.2.4.zip 插件,elasticsearch-analysis-ik-6.2.4.zip 插件
ElasticSearch安装分词插件 elasticsearch是支持中文的ik分词器,本版本支持elasticsearch7.5.2
本plugins插件根据elasticsearch-analysis-ik2.2.0基础上修改编译,支持elasticsearch2.2.0(已测)。此IKAnalyzer增加连续数字、字母、英语及其组合智能分词(ik_smart、ik_max_word、ik_indistinct、ik_smart_in...
修改了IK analysis插件,使能够兼容elasticsearch 2.0。 感谢:IKAnalyzer用于Lucene5的文件,http://www.oschina.net/code/snippet_97202_48660
ELK6.1.2,filebeat及es的常用head和ik插件,ELK6.1.2,filebeat及es的常用head和ik插件
es插件之ik分词器插件(适用于es6.8版本)