ElasticSearch(四) ElasticSearch中文分词插件IK的简单测试

2023-05-22,,

先来一个简单的测试

# curl -XPOST  "http://192.168.9.155:9200/_analyze?analyzer=standard&pretty" -d 'PHP是世界上最好的语言'   //_analyze表示分析分词;analyzer=standard,表示分词方式standard; -d表示测试的一段文字

测试结果

{
"tokens" : [
{
"token" : "php",
"start_offset" : ,
"end_offset" : ,
"type" : "<ALPHANUM>",
"position" :
},
{
"token" : "是",
"start_offset" : ,
"end_offset" : ,
"type" : "<IDEOGRAPHIC>",
"position" :
},
{
"token" : "世",
"start_offset" : ,
"end_offset" : ,
"type" : "<IDEOGRAPHIC>",
"position" :
},
{
"token" : "界",
"start_offset" : ,
"end_offset" : ,
"type" : "<IDEOGRAPHIC>",
"position" :
},
{
"token" : "上",
"start_offset" : ,
"end_offset" : ,
"type" : "<IDEOGRAPHIC>",
"position" :
},
{
"token" : "最",
"start_offset" : ,
"end_offset" : ,
"type" : "<IDEOGRAPHIC>",
"position" :
},
{
"token" : "好",
"start_offset" : ,
"end_offset" : ,
"type" : "<IDEOGRAPHIC>",
"position" :
},
{
"token" : "的",
"start_offset" : ,
"end_offset" : ,
"type" : "<IDEOGRAPHIC>",
"position" :
},
{
"token" : "语",
"start_offset" : ,
"end_offset" : ,
"type" : "<IDEOGRAPHIC>",
"position" :
},
{
"token" : "言",
"start_offset" : ,
"end_offset" : ,
"type" : "<IDEOGRAPHIC>",
"position" :
}
]
}

接下来使用我们的IK

ik 带有两个分词器 
ik_max_word :会将文本做最细粒度的拆分;尽可能多的拆分出词语,拼接各种可能的组合 。
ik_smart:会做最粗粒度的拆分;已被分出的词语将不会再次被其它词语占有 。

curl -XPOST  "http://192.168.9.155:9200/_analyze?analyzer=ik_smart&pretty" -d 'PHP是世界上最好的语言'  //ik_smart方式
{
"tokens" : [
{
"token" : "php",
"start_offset" : ,
"end_offset" : ,
"type" : "ENGLISH",
"position" :
},
{
"token" : "世界上",
"start_offset" : ,
"end_offset" : ,
"type" : "CN_WORD",
"position" :
},
{
"token" : "最好",
"start_offset" : ,
"end_offset" : ,
"type" : "CN_WORD",
"position" :
},
{
"token" : "语言",
"start_offset" : ,
"end_offset" : ,
"type" : "CN_WORD",
"position" :
}
]
}
curl -XPOST  "http://192.168.9.155:9200/_analyze?analyzer=ik_max_word&pretty" -d 'PHP是世界上最好的语言'    //ik_max_word方式
{
"tokens" : [
{
"token" : "php",
"start_offset" : ,
"end_offset" : ,
"type" : "ENGLISH",
"position" :
},
{
"token" : "世界上",
"start_offset" : ,
"end_offset" : ,
"type" : "CN_WORD",
"position" :
},
{
"token" : "世界",
"start_offset" : ,
"end_offset" : ,
"type" : "CN_WORD",
"position" :
},
{
"token" : "上",
"start_offset" : ,
"end_offset" : ,
"type" : "CN_CHAR",
"position" :
},
{
"token" : "最好",
"start_offset" : ,
"end_offset" : ,
"type" : "CN_WORD",
"position" :
},
{
"token" : "语言",
"start_offset" : ,
"end_offset" : ,
"type" : "CN_WORD",
"position" :
}
]
}

区别很明显~

ElasticSearch(四) ElasticSearch中文分词插件IK的简单测试的相关教程结束。

《ElasticSearch(四) ElasticSearch中文分词插件IK的简单测试.doc》

下载本文的Word格式文档,以方便收藏与打印。