Elasticsearch 6.5.4 安装IK Analysis插件

1.找到合适的版本

IK versionES version
6.1.16.1.1
5.6.45.6.4
5.5.35.5.3
5.4.35.4.3
5.3.35.3.3
5.2.25.2.2
5.1.25.1.2
1.10.62.4.6
1.9.52.3.5
1.8.12.2.1
1.7.02.1.1
1.5.02.0.0
1.2.61.0.0
1.2.50.90.x
1.1.30.20.x
1.0.00.16.2 -> 0.19.0

 

 

 

 

 

 

 

 

 

 

 

 

 

2.下载对应的zip包

对应版本的zip包

在本地elasticsearch根目录下的plugins下新建ik文件夹,将zip包中内容解压到该文件夹下。

现在重启es就可以了

3. 安装kibana进场测试

创建index,type

PUT /yf-springboot-es-ik1

POST /yf-springboot-es-ik1/springboot-test/_mapping
{
  "springboot-test": {
    "properties": {
      "keyword": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_max_word"
        
      }
    }
  }
}

 

使用浏览器进行测试:

http://localhost:9200/yf-springboot-es-ik1/springboot-test/14/_termvectors?fields=keyword

ip + 端口 + index + type + id + _termvectors + ?fields = 搜索字段

POST /yf-springboot-es-ik1/springboot-test/14
{"keyword":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
{
    "_index": "yf-springboot-es-ik1",
    "_type": "springboot-test",
    "_id": "14",
    "_version": 4,
    "found": true,
    "took": 0,
    "term_vectors": {
        "keyword": {
            "field_statistics": {
                "sum_doc_freq": 14,
                "doc_count": 1,
                "sum_ttf": 14
            },
            "terms": {
                "中国": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 0,
                            "start_offset": 0,
                            "end_offset": 2
                        }
                    ]
                },
                "亚裔": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 7,
                            "start_offset": 10,
                            "end_offset": 12
                        }
                    ]
                },
                "嫌犯": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 11,
                            "start_offset": 17,
                            "end_offset": 19
                        }
                    ]
                },
                "子枪": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 9,
                            "start_offset": 13,
                            "end_offset": 15
                        }
                    ]
                },
                "": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 12,
                            "start_offset": 19,
                            "end_offset": 20
                        }
                    ]
                },
                "枪击": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 10,
                            "start_offset": 14,
                            "end_offset": 16
                        }
                    ]
                },
                "洛杉矶": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 2,
                            "start_offset": 3,
                            "end_offset": 6
                        }
                    ]
                },
                "男子": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 8,
                            "start_offset": 12,
                            "end_offset": 14
                        }
                    ]
                },
                "自首": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 13,
                            "start_offset": 20,
                            "end_offset": 22
                        }
                    ]
                },
                "": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 6,
                            "start_offset": 9,
                            "end_offset": 10
                        }
                    ]
                },
                "领事": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 4,
                            "start_offset": 6,
                            "end_offset": 8
                        }
                    ]
                },
                "领事馆": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 3,
                            "start_offset": 6,
                            "end_offset": 9
                        }
                    ]
                },
                "": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 5,
                            "start_offset": 8,
                            "end_offset": 9
                        }
                    ]
                },
                "": {
                    "term_freq": 1,
                    "tokens": [
                        {
                            "position": 1,
                            "start_offset": 2,
                            "end_offset": 3
                        }
                    ]
                }
            }
        }
    }
}

 使用kibana添加数据并且查询

POST /yf-springboot-es-ik1/springboot-test/11
{"keyword":"美国留给伊拉克的是个烂摊子吗"}

POST /yf-springboot-es-ik1/springboot-test/12
{"keyword":"公安部:各地校车将享最高路权"}

POST /yf-springboot-es-ik1/springboot-test/13
{"keyword":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}

POST /yf-springboot-es-ik1/springboot-test/14
{"keyword":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}

POST /yf-springboot-es-ik1/springboot-test/_search
{
    "query" : { "match" : { "keyword" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "keyword" : {}
        }
    }
}

查询结果:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 0.5480699,
    "hits" : [
      {
        "_index" : "yf-springboot-es-ik1",
        "_type" : "springboot-test",
        "_id" : "13",
        "_score" : 0.5480699,
        "_source" : {
          "keyword" : "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
        },
        "highlight" : {
          "keyword" : [
            "中韩渔警冲突调查:韩警平均每天扣1艘<tag1>中国</tag1>渔船"
          ]
        }
      },
      {
        "_index" : "yf-springboot-es-ik1",
        "_type" : "springboot-test",
        "_id" : "14",
        "_score" : 0.2876821,
        "_source" : {
          "keyword" : "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
        },
        "highlight" : {
          "keyword" : [
            "<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
          ]
        }
      }
    ]
  }
}

 

4.ik_max_word 和 ik_smart 什么区别?

ik_max_word: 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合;

ik_smart: 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”

转载于:https://www.cnblogs.com/yangfei-beijing/p/10220983.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值