ElasticStack学习笔记(三)

第三章  ElasticSearch

3.1 分词

3.1.1 分词简介

分词:语言识别,讲一句话分为多个单词就是分词。默认使用标准分词器;

分词器 接受一个字符串作为输入,将这个字符串拆分成独立的词或 语汇单元(token) (可能会丢弃一些标点符号等字符),然后输出一个 语汇单元流(token stream) 。

POST  http://172.31.132.130:9200/_analyze
{
    "analyzer":"standard",
    "text": "hell word"
}

{
    "tokens": [
        {
            "token": "hell",
            "start_offset": 0,
            "end_offset": 4,
            "type": "<ALPHANUM>",
            "position": 0
        },
        {
            "token": "word",
            "start_offset": 5,
            "end_offset": 9,
            "type": "<ALPHANUM>",
            "position": 1
        }
    ]
}

 标准分词器,英文分词比较好,中文分词就很一般,我是中国人, 分词应该是: 我 / 是中国人/ ,  这样比较好,但是默认的一个一个字分开了,不是特别好的。 

{
    "analyzer":"standard",
    "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
        }
    ]
}

 指定索引分词: 

http://172.31.132.130:9200/index_test_02/_analyze
{
    "analyzer":"standard",
    "field":"hobby",
    "text": "音乐"
}

 3.1.1  中文分词

 中文分词:容易产生歧义,不好理解,需要使用专用中文分词分析;

 常见的中文分词器 : IK分词器;

安装IK 分词器 : 需要版本和es版本一致 : https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.3.0

下载IK包,解压到plugis目录下,重新启动即可

POST http://172.31.132.130:9200/index_test_02/_analyze

{
    "analyzer":"ik_smart",
    "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
        }
    ]
}

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值