一.什么是分词?
把文本转换为一个个的单词,分词称之为analysis。es默认只对英文语句做分词,中文不支持,每个中文字都会被拆分为独立的个体。
POST /_analyze
{
"analyzer": "standard",
"text": "text文本"
}
POST /my_doc/_analyze
{
"analyzer": "standard",
"field": "name",
"text": "text文本"
}
二.ES内置分词器
- standard:默认分词,单词会被拆分,大小会转换为小写。
- simple:按照非字母分词。大写转为小写。
- whitespace:按照空格分词。忽略大小写。
- stop:去除无意义单词,比如the/a/an/is…
- keyword:不做分词。把整个文本作为一个单独的关键词。
{
"analyzer": "standard",
"text": "My name is Peter Parker,I am a Super Hero. I don't like the Criminals."
}
三.添加中文分词
{
"analyzer":"ik_smart",
"text":"好好学习天天向上"
{
"tokens": [
{
"token": "好好学习",
"start_offset": 0,
"end_offset": 4,
"type": "CN_WORD",
"position": 0
},
{
"token": "天天向上",
"start_offset": 4,
"end_offset": 8,
"type": "CN_WORD",
"position": 1
}
]
}
}

image.png