Elasticsearch安装ik插件
想要给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/indexcurl -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 } ]}
?
?
?
?
?
?
?
?
?
?请支持原创:
?
?
?
?
?
对这类话题感兴趣?欢迎发送邮件至donlianli@126.com关于我:邯郸人,擅长Java,Javascript,Extjs,oracle sql。更多我之前的文章,可以访问?我的空间?