码迷,mamicode.com
首页 > 其他好文 > 详细

elasticsearch IK中文分词

时间:2015-07-21 23:43:00      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

1. analysis-ik安装


1). 从 https://github.com/medcl/elasticsearch-analysis-ik ,下载 elasticsearch-analysis-ik-master.zip

 
2). 解压后,
     cd  elasticsearch-analysis-ik-master
     /usr/local/maven/bin/mvn package                
     .... wait  5-6分钟
    
    编译成功后,
    拿到target/releases/下的zip包,上传到服务器上
    上config目录的ik文件夹到服务器上
 
3). 安装插件
    /usr/share/elasticsearch/bin/plugin -i analysis-ik -u file:///soft/elasticsearch-analysis-ik-1.3.0.zip (本地安装)
    /usr/share/elasticsearch/bin/plugin -i analysis-ik ftp://10.104.16.43/es/analysis-ik/elasticsearch-analysis-ik-1.3.0.zip (内网安装)
    scp -r ./ik $ip:/etc/elasticsearch/
    echo ‘index.analysis.analyzer.ik.type : "ik"‘ >> /etc/elasticsearch/elasticsearch.yml
 
4).重启集群
   
 
2. analysis-ik测试

导入测试数据
  1. [root@VM_16_43_centos analysis-ik]# cat iktest.sh
  2. #1.creat a index
  3. curl -XPUT http://localhost:9200/iktest
  4. #2.create a mapping
  5. curl -XPOST http://localhost:9200/iktest/fulltext/_mapping -d
  6. {
  7. "fulltext": {
  8. "_all": {
  9. "indexAnalyzer": "ik",
  10. "searchAnalyzer": "ik",
  11. "term_vector": "no",
  12. "store": "false"
  13. },
  14. "properties": {
  15. "content": {
  16. "type": "string",
  17. "store": "no",
  18. "term_vector": "with_positions_offsets",
  19. "indexAnalyzer": "ik",
  20. "searchAnalyzer": "ik",
  21. "include_in_all": "true",
  22. "boost": 8
  23. }
  24. }
  25. }
  26. }‘
  27. #3.iktest index some docs
  28. curl -XPOST http://localhost:9200/iktest/fulltext/1-d
  29. {"content":"美国留给伊拉克的是个烂摊子吗"}
  30. curl -XPOST http://localhost:9200/iktest/fulltext/2-d
  31. {"content":"公安部:各地校车将享最高路权"}
  32. curl -XPOST http://localhost:9200/iktest/fulltext/3-d
  33. {"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
  34. curl -XPOST http://localhost:9200/iktest/fulltext/4-d
  35. {"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
  1. [root@VM_16_43_centos analysis-ik]# sh iktest.sh
  2. {"acknowledged":true}
  3. {"acknowledged":true}
  4. {"_index":"iktest","_type":"fulltext","_id":"1","_version":1,"created":true}
  5. {"_index":"iktest","_type":"fulltext","_id":"2","_version":1,"created":true}
  6. {"_index":"iktest","_type":"fulltext","_id":"3","_version":1,"created":true}
  7. {"_index":"iktest","_type":"fulltext","_id":"4","_version":1,"created":true}
查询数据
1)搜索“男子”
技术分享
 
2) 搜索“公安”
技术分享





elasticsearch IK中文分词

标签:

原文地址:http://www.cnblogs.com/51runsky/p/4665793.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!