为Elasticsearch安装中文分词IK

 

注:Elasticsearch版本:1.4.2

一、安装与配置

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

2.解压elasticsearch-analysis-ik-master.zip

   unzip elasticsearch-analysis-ik-master.zip

3.进入elasticsearch-analysis-ik-master,编译源码

  cd  elasticsearch-analysis-ik-master

  mvn clean install -Dmaven.test.skip=true 

4.在$ES_HOME/plugins文件夹下创建analysis-ik

    mkdir analysis-ik

5.将编译后生成的elasticsearch-analysis-ik-1.2.9.zip移到$ES_HOME/plugins/analysis-ik下,并解压。

编译后elasticsearch-analysis-ik-1.2.9.zip的生成位置

 技术分享

6.将config下的ik文件夹复制到$ES_HOME/config/下

7.修改$ES_HOME/config/elasticsearch.yml 

 

 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

  

#或

  index.analysis.analyzer.ik.type : “ik”

 

8.重启Elasticsearch

二、测试

1.创建索引index

curl -XPUT http://localhost:9200/index

2.创建mapping

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

            }

        }

    }

}‘

3.索引一些数据

curl -XPOST http://localhost:9200/index/fulltext/1 -d‘

{"content":"东北大学是教育部直属的国家重点大学,坐落在东北中心城市沈阳。学校占地总面积261万平方米,建筑面积123万平方米。"}

curl -XPOST http://localhost:9200/index/fulltext/2 -d‘

{"content":"东北大学在秦皇岛设立的分校。 东北大学秦皇岛分校是经教育部正式批准成立."}

curl -XPOST http://localhost:9200/index/fulltext/3 -d‘

{"content":"东北大学秦皇岛分校是经教育部正式批准成立,在东北大学统一规划下,面向全国招生,相对独立办学的普通高等学校。学校始建于1987年,是东北大学的有机组成部分."}

curl -XPOST http://localhost:9200/index/fulltext/4 -d‘

{"content":"东软 英文名称Neusoft,东软是中国领先的IT解决方案与服务供应商。1991年,东软创立于中国东北大学。公司主营业务包括:行业解决方案、产品工程解决方案及相关软件产品、平台及服务等。"}

4.查询

curl -XPOST http://localhost:9200/index/fulltext/_search  -d‘

{

    "query" : { "term" : { "content" : "东北大学" }},

    "highlight" : {

        "pre_tags" : ["<tag1>", "<tag2>"],

        "post_tags" : ["</tag1>", "</tag2>"],

        "fields" : {

            "content" : {}

        }

    }

}

5、通过Kibana4.0进行搜索

①首先修改配置,依次点击编辑按钮,如图所示:

 技术分享

②添加新的配置

 技术分享

把Index contains time-based events取消

在Index name of pattern内输入“index”,点击Create

③回到查询界面,选择index进行查询。

 技术分享

技术分享

 

 参考:https://github.com/medcl/elasticsearch-analysis-ik

 

 

文章来自:http://www.cnblogs.com/lambertzhao/p/4244732.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3