当前位置:   article > 正文

es--基础--05--集成IK分词器_es ik分词器

es ik分词器

es–基础–05–集成IK分词器


1、标准分词存在的问题

1.1、当前的数据

在这里插入图片描述

1.2、标准分词器

在这里插入图片描述

1.3、标准分词存在的问题

在这里插入图片描述

但是我们有"两头"的数据

在这里插入图片描述

1.4、标准分词器分词效果测试

在这里插入图片描述

http://60.205.188.229:9200/_analyze?analyzer=standard&pretty=true&text=我是程序员

{
    "tokens": [
        {
            "token": "我",
            "start_offset": 0,
            "end_offset": 1,
            "type": "<IDEOGRAPHIC>",
            "position": 0
        },
        {
            "token": "是",
            "start_offset": 1,
            "end_offset": 2,
            "type": "<IDEOGRAPHIC>",
            "position": 1
        },
        {
            "token": "程",
            "start_offset": 2,
            "end_offset": 3,
            "type": "<IDEOGRAPHIC>",
            "position": 2
        },
        {
            "token": "序",
            "start_offset": 3,
            "end_offset": 4,
            "type": "<IDEOGRAPHIC>",
            "position": 3
        },
        {
            "token": "员",
            "start_offset": 4,
            "end_offset": 5,
            "type": "<IDEOGRAPHIC>",
            "position": 4
        }
    ]
}
  • 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
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  1. 我们可以看到标准分词器是基于每个单词进行分词的
  2. 而我们期望的分词如下
    1. 程序
    2. 程序员
  3. IK分词器可以满足我们的期望

2、IK分词器简介

  1. 名称:IKAnalyzer
  2. 是一个开源的,基于java语言开发的轻量级的中文分词工具包。
  3. 它是以开源项目Lucene为应用主体的,结合词典分词和文法分析算法的中文分词组件。
  4. 新版本的IKAnalyzer3.0则发展为 面向Java的公用分词组件,独立于Lucene项目,同时提供了对Lucene的默认优化实现。

2.1、IK分词器3.0的特性

  1. 采用"正向迭代最细粒度切分算法",具有60万字/秒的高速处理能力。
  2. 采用多子处理器分析模式,支持以下分词处理
    1. 英文字母(IP地址、Email、URL)
    2. 数字(日期,常用中文数量词,罗马数字,科学计数法)
    3. 中文词汇(姓名、地名处理)。
  3. 对中英联合支持不是很好,在这方面的处理比较麻烦,需再做一次查询
  4. 支持个人词条的优化的词典存储,更小的内存占用。
  5. 支持用户词典扩展定义。
  6. 针对Lucene全文检索优化的查询分析器IKQueryParser
    1. 采用歧义分析算法优化查询关键字的搜索排列组合,能极大的提高Lucene检索的命中率。

3、es集成IK分词器

  1. 提供了两个分词算法
    1. ik_smart:最少切分
    2. ik_max_word:最细粒度划分

3.1、IK分词器的安装

  1. 关闭原来ES服务器

  2. 切换elsearch用户

  3. 解压elasticsearch-analysis-ik-5.6.8.zip
    unzip elasticsearch-analysis-ik-5.6.8.zip

    在这里插入图片描述

  4. 移动解压出来的elasticsearch

     [elsearch@zhoufei elasticsearch]$ mv elasticsearch /usr/local/java/elasticsearch/elasticsearch-5.6.8/plugins
    
    • 1
  5. 重启启动ES服务器

3.2、IK分词器分词效果测试

3.2.1、ik_smart测试

http://60.205.188.229:9200/_analyze?analyzer=ik_smart&pretty=true&text=我是程序员

{
    "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
        }
    ]
}
  • 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
  • 27

3.2.2、ik_max_word测试

http://60.205.188.229:9200/_analyze?analyzer=ik_max_word&pretty=true&text=我是程序员

{
    "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
        },
        {
            "token": "程序",
            "start_offset": 2,
            "end_offset": 4,
            "type": "CN_WORD",
            "position": 3
        },
        {
            "token": "员",
            "start_offset": 4,
            "end_offset": 5,
            "type": "CN_CHAR",
            "position": 4
        }
    ]
}
  • 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
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

3.3、文档测试

3.3.1、删除以前的索引,重新定义mapping,使用ik_smart分词器

http://60.205.188.229:9200/blog4

{
	"mappings": {
		"article": {
			"properties": {
				"id": {
					"type": "long",
					"store": true,
					"index":"not_analyzed"
				},
				"title": {
					"type": "text",
					"store": true,
					"index":"analyzed",
					"analyzer":"ik_smart"
				},
				"content": {
					"type": "text",
					"store": true,
					"index":"analyzed",
					"analyzer":"ik_smart"
				}
			}
		}
	}
}
  • 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
  • 27

3.3.2、重新加载数据

在这里插入图片描述

3.3.3、测试

在这里插入图片描述

在这里插入图片描述

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号