ES ik中文分词器的安装

ik分词是一款流行的elasticsearch 中文分词器,安装ik分词器版本一定要与所安装es版本一致。

安装步骤:

1、解压ik分词器安装包到plugin目录下,并删除压缩包。

2、重启elasticsearch进程即可。

3、如果是es集群的话,每台es都需要安装ik分词器。

测试:

Curl "http://ES_IP:9200/_analyze?analyzer=ik_smart&pretty=true&text=%E6%88%91%E6%98%AF%E4%B8%AD%E5%9B%BD%E4%BA%BA"

结果如下则安装成功:

{
  "tokens" : [
    {
      "token" : "我",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "CN_CHAR",
      "position" : 0
    },
    {
      "token" : "是",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "CN_CHAR",
      "position" : 1
    },
    {
      "token" : "中国人",
      "start_offset" : 2,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 2
    }
  ]

}

ik安装完成后,需要重新构建mapping才能生效:

例如给data字段进行分词,需要修改mapping中data的配置为:

"data": {"search_analyzer": "ik_smart",
"analyzer": "ik_max_word",
"type": "text"
}

原文地址:https://www.cnblogs.com/hel7512/p/12350563.html