【ES2】分词器

一、分词与内置分词器
  1. 默认的standard分词器。能够把英文单词进行拆分,同时会把大小的字母自动转化成小写。
    在这里插入图片描述
    url

http://47.107.41.60:9200/_analyze psot

传入的json

{
“analyzer”:“standard”,
“text”:“My name is Xiaohei”
}

返回的结果

{
“tokens”: [
{
“token”: “my”,
“start_offset”: 0,
“end_offset”: 2,
“type”: “”,
“position”: 0
},
{
“token”: “name”,
“start_offset”: 3,
“end_offset”: 7,
“type”: “”,
“position”: 1
},
{
“token”: “is”,
“start_offset”: 8,
“end_offset”: 10,
“type”: “”,
“position”: 2
},
{
“token”: “xiaohei”,
“start_offset”: 11,
“end_offset”: 18,
“type”: “”,
“position”: 3
}
]
}

  1. simple分词器
    会把数字和符号剔除掉,也会把大写转成小写

  2. whitespace对空格进行拆分,不会把大写转化成小写

  3. stop分词器 会把没有意义的单词去除,比如a,the,is等等。

  4. keyword不会进行拆分。

在这里插入图片描述
在这里插入图片描述

二、ik中文分词器
1. 安装
  1. 在github上搜索ik,并下载对应的zip压缩包,上传到linux上。

  2. 解压文件到es的pluigins下。
    在这里插入图片描述

  3. 重启就可以使用了

2. ik_max_word

最细粒度进行拆分
在这里插入图片描述
结果

{
    "tokens": [
        {
            "token": "今天天气",
            "start_offset": 0,
            "end_offset": 4,
            "type": "CN_WORD",
            "position": 0
        },
        {
            "token": "今天",
            "start_offset": 0,
            "end_offset": 2,
            "type": "CN_WORD",
            "position": 1
        },
        {
            "token": "天天",
            "start_offset": 1,
            "end_offset": 3,
            "type": "CN_WORD",
            "position": 2
        },
        {
            "token": "天气",
            "start_offset": 2,
            "end_offset": 4,
            "type": "CN_WORD",
            "position": 3
        },
        {
            "token": "很好",
            "start_offset": 4,
            "end_offset": 6,
            "type": "CN_WORD",
            "position": 4
        }
    ]
}
3. ik_smart

最粗粒度进行拆分

结果:

{
    "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
        }
    ]
}
4. 区别

在这里插入图片描述

三、自定义中文词库

有些时候我们可能需要自己添加词汇库
进入IKAnalyzer.cfg.xml
在这里插入图片描述
在这里插入图片描述
增加一个wy.dic文件
在这里插入图片描述

写上内容,并重启

在这里插入图片描述
结果如下:

{
    "tokens": [
        {
            "token": "骚年",
            "start_offset": 0,
            "end_offset": 2,
            "type": "CN_WORD",
            "position": 0
        },
        {
            "token": "年在",
            "start_offset": 1,
            "end_offset": 3,
            "type": "CN_WORD",
            "position": 1
        },
        {
            "token": "慕课网",
            "start_offset": 3,
            "end_offset": 6,
            "type": "CN_WORD",
            "position": 2
        },
        {
            "token": "学习",
            "start_offset": 6,
            "end_offset": 8,
            "type": "CN_WORD",
            "position": 3
        }
    ]
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逸羽菲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值