栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

ElasticSearch 安装IK分词器

ElasticSearch 安装IK分词器

文章目录
  • 1,ES安装ik分词器
  • 2,测试使用

1,ES安装ik分词器

IK分词器下载参考:https://gitcode.net/mirrors/medcl/elasticsearch-analysis-ik

#1. ES安装IK分词器:ES版本:5.4.3 == IK分词器版本:5.4.3
# ES-IK分词器下载:https://github.com/medcl/elasticsearch-analysis-ik/releases?page=12
# https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.4.3/elasticsearch-analysis-ik-5.4.3.zip

#查看ES版本
[root@daas4 ~]# curl localhost:9200
{
  "name" : "daas4",
  "cluster_name" : "dass-es",
  "cluster_uuid" : "D89bKW29TlyGul9qELxXwQ",
  "version" : {
    "number" : "5.4.3",
    "build_hash" : "eed30a8",
    "build_date" : "2017-06-22T00:34:03.743Z",
    "build_snapshot" : false,
    "lucene_version" : "6.5.1"
  },
  "tagline" : "You Know, for Search"
}

#离线安装plugin
[root@daas4 elasticsearch-5.4.3]# cd plugins/
[root@daas4 plugins]# mkdir ik ; ls
ik
[root@daas4 plugins]# unzip ../elasticsearch-analysis-ik-5.4.3.zip -d ik/
Archive:  ../elasticsearch-analysis-ik-5.4.3.zip
  inflating: ik/plugin-descriptor.properties  
   creating: ik/config/
   creating: ik/config/custom/
  inflating: ik/config/custom/ext_stopword.dic  
  inflating: ik/config/custom/mydict.dic  
  inflating: ik/config/custom/single_word.dic  
  inflating: ik/config/custom/single_word_full.dic  
  inflating: ik/config/custom/single_word_low_freq.dic  
  inflating: ik/config/custom/sougou.dic  
  inflating: ik/config/IKAnalyzer.cfg.xml  
  inflating: ik/config/main.dic      
  inflating: ik/config/preposition.dic  
  inflating: ik/config/quantifier.dic  
  inflating: ik/config/stopword.dic  
  inflating: ik/config/suffix.dic    
  inflating: ik/config/surname.dic   
  inflating: ik/elasticsearch-analysis-ik-5.4.3.jar  
  inflating: ik/httpclient-4.5.2.jar  
  inflating: ik/httpcore-4.4.4.jar   
  inflating: ik/commons-logging-1.2.jar  
  inflating: ik/commons-codec-1.9.jar  
  
[root@daas4 plugins]# /export/server/elasticsearch-5.4.3/bin/elasticsearch-plugin list
elasticsearch
ik

[root@daas4 plugins]# ll ik/
total 1424
-rw-r--r-- 1 root root 263965 Dec 16 15:51 commons-codec-1.9.jar
-rw-r--r-- 1 root root  61829 Sep 13 09:36 commons-logging-1.2.jar
drwxr-xr-x 3 root root   4096 Jul  1  2017 config
-rw-r--r-- 1 root root  51409 Dec 16 16:12 elasticsearch-analysis-ik-5.4.3.jar
-rw-r--r-- 1 root root 736658 Sep 13 09:46 httpclient-4.5.2.jar
-rw-r--r-- 1 root root 326724 Dec 16 15:51 httpcore-4.4.4.jar
-rw-r--r-- 1 root root   2666 Dec 16 16:12 plugin-descriptor.properties
2,测试使用
#2. 测试ik分词
[root@daas4 plugins]# curl -XPOST http://localhost:9200/_analyze?pretty  -H 'Content-Type:application/json' -d '
{  
    "analyzer": "ik_max_word",
    "text": "我们是中国人"  
}'

result===>
{
  "tokens" : [
    {
      "token" : "我们",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "中国人",
      "start_offset" : 3,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "中国",
      "start_offset" : 3,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "国人",
      "start_offset" : 4,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 3
    }
  ]
}


#3. 创建索引,指定字段解析器和类型
[root@daas4 plugins]#  curl -XPUT localhost:9200/test_ik?pretty   -H "Content-Type: application/json" -d '
{
    "mappings": {
        "_default_": {
            "_all": {
                "enabled": false
            },
            "properties": {
                "tableSuffix": {
                    "index": true,
                    "store": true,
                    "type": "keyword"
                },
                "databaseName": {
                    "search_analyzer": "ik_max_word",
                    "analyzer": "ik_max_word",
                    "index": true,
                    "store": true,
                    "type": "text"
                },
                "tableId": {
                    "index": true,
                    "store": true,
                    "type": "keyword"
                }
            }
        }
    }
}'

result==>
{
  "acknowledged" : true,
  "shards_acknowledged" : true
}


[root@daas4 plugins]#  curl localhost:9200/_cat/indices?v
health status index                            uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   test10                           uX9kL6HzRL-jrwdbaKmd5Q   5   1          0            0       795b           795b
yellow open   test_ik                          JLNthJcmQQO1416Td4ldUQ   5   1          0            0       650b           650b
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/670928.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号