大数据运维(40)ElasticSearch安装ik中文分词器

官方文档:

1
https://github.com/medcl/elasticsearch-analysis-ik

创建目录:

1
2
cd xxx/plugins/
mkdir ik

查看版本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# curl -XGET localhost:9200
{
  "name" "es1",
  "cluster_name" "vphotoses",
  "cluster_uuid" "1q0u6R63QXGGgcfVegPqQg",
  "version" : {
    "number" "5.3.0",
    "build_hash" "3adb13b",
    "build_date" "2017-03-23T03:31:50.652Z",
    "build_snapshot" false,
    "lucene_version" "6.4.1"
  },
  "tagline" "You Know, for Search"
}

下载插件:版本号要和elasticsearch完全一致,否者安装失败es重启不了。

1
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.3.0/elasticsearch-analysis-ik-5.3.0.zip

解压到ik目录即可:

1
unzip elasticsearch-analysis-ik-5.3.0.zip

重启elasticsearch即可。

查看已经安装的插件:

1
2
3
# curl -XGET localhost:9200/_cat/plugins
es1 analysis-ik 5.3.0
es2 analysis-ik 5.3.0

使用分词:

在命令行中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# curl -XGET 'http://localhost:9200/_analyze?pretty&analyzer=ik_smart' -d '五星红旗迎风飘扬'
{
  "tokens" : [
    {
      "token" "五星红旗",
      "start_offset" : 0,
      "end_offset" : 4,
      "type" "CN_WORD",
      "position" : 0
    },
    {
      "token" "迎风",
      "start_offset" : 4,
      "end_offset" : 6,
      "type" "CN_WORD",
      "position" : 1
    },
    {
      "token" "飘扬",
      "start_offset" : 6,
      "end_offset" : 8,
      "type" "CN_WORD",
      "position" : 2
    }
  ]
}

或打开如下web页面

1
http://10.64.104.43:5601/app/kibana#/dev_tools/console?_g=()

在console输入框中输入如下内容再点击发送按钮:

1
2
3
4
5
post  _analyze
{
    "text":"五星红旗迎风飘扬"
    ,"analyzer":"ik_max_word"
}

image.png

作者:大码王

-------------------------------------------

个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!

如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•?ω•?)っ???!

原文地址:https://www.cnblogs.com/huanghanyu/p/13746104.html