为什么需要自定义分词
常见的文本,ik可以很好的分词,但有些特殊内容,如:人名,网络热词等,ik就不能很好的支持
比如:马育民的博客,就不能识别人名,无法很好的分词
get /myblog/_analyze
{
"analyzer":"ik_smart",
"text":"马育民的博客"
}
get /myblog/_analyze
{
"analyzer":"ik_max_word",
"text":"马育民的博客"
}
上面2种分词策略,都不能很好的分词,执行结果如下:
{
"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" : 3,
"type" : "CN_CHAR",
"position" : 2
},
{
"token" : "的",
"start_offset" : 3,
"end_offset" : 4,
"type" : "CN_CHAR",
"position" : 3
},
{
"token" : "博客",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 4
}
]
}
解决方法
需要自定义分词: