最近更新时间:2024.04.07 19:15:43
首次发布时间:2023.07.21 11:36:53
当您上传并启用 IK 分词词典文件后,您可以直接体验 IK 分词能力。本文提供一个简单示例,以帮助您了解如何使用 IK 分词。
本文提供两个示例词典文件,帮助您快速了解和使用 IK 分词。
提供一个主分词词典文件(DOC_MAIN.dic),词典内容如下:
云搜索服务 重要功能
提供一个停用词词典文件(DOC_STOPWORD.dic),词典内容如下:
的 一个 是
本文选择登录可视化工具进行索引相关操作,请先启用公网访问能力。具体操作,请参见配置 Kibana/Dashboards 公网访问。
登录云搜索服务控制台。
在顶部导航栏,选择目标实例所在的地域。
您可通过以下方式访问可视化工具登录页面:
说明
云搜索服务控制台,支持 ES 和 OpenSearch 两种实例。ES 实例的可视化工具为 Kibana;OpenSearch 实例的可视化工具为 Dashboards。
在登录页面输入用户名和密码,登录可视化工具。
用户名为 admin,密码为创建实例时设置的密码。如果您忘记了登录密码,您可在实例详情页面重置密码。
在左侧导航栏选择Management > Dev Tools,然后在代码区域执行以下命令,创建索引。
PUT /doctest { "settings": { "number_of_shards": 1 }, "mappings": { "properties": { "subject": { "type": "text" } } } }
执行以下命令查询数据,测试 IK 分词插件是否正常可用。
GET /doctest/_analyze { "analyzer": "ik_smart", "text": ["云搜索服务的IK分词是一个重要功能"] }
说明
IK分词插件的分词器包括ik_smart
和ik_max_word
,两者区别如下:
云搜索服务
,拆分返回结果为云,搜索,服务
。云搜索服务
,拆分返回结果为云搜索,搜索,服务
。
返回的完成信息如下:
{ "tokens" : [ { "token" : "云", "start_offset" : 0, "end_offset" : 1, "type" : "CN_CHAR", "position" : 0 }, { "token" : "搜索", "start_offset" : 1, "end_offset" : 3, "type" : "CN_WORD", "position" : 1 }, { "token" : "服务", "start_offset" : 3, "end_offset" : 5, "type" : "CN_WORD", "position" : 2 }, { "token" : "的", "start_offset" : 5, "end_offset" : 6, "type" : "CN_CHAR", "position" : 3 }, { "token" : "ik", "start_offset" : 6, "end_offset" : 8, "type" : "ENGLISH", "position" : 4 }, { "token" : "分词", "start_offset" : 8, "end_offset" : 10, "type" : "CN_WORD", "position" : 5 }, { "token" : "是", "start_offset" : 10, "end_offset" : 11, "type" : "CN_CHAR", "position" : 6 }, { "token" : "一个", "start_offset" : 11, "end_offset" : 13, "type" : "CN_WORD", "position" : 7 }, { "token" : "重要", "start_offset" : 13, "end_offset" : 15, "type" : "CN_WORD", "position" : 8 }, { "token" : "功能", "start_offset" : 15, "end_offset" : 17, "type" : "CN_WORD", "position" : 9 } ] }
上传并启动主分词词典文件(DOC_MAIN.dic),然后重新执行查询命令,注意对比前后两次的查询结果。
如何上传词典文件,请参见上传 IK 分词词典文件。
{ "tokens" : [ { "token" : "云搜索服务", "start_offset" : 0, "end_offset" : 5, "type" : "CN_WORD", "position" : 0 }, { "token" : "的", "start_offset" : 5, "end_offset" : 6, "type" : "CN_CHAR", "position" : 1 }, { "token" : "ik", "start_offset" : 6, "end_offset" : 8, "type" : "ENGLISH", "position" : 2 }, { "token" : "分词", "start_offset" : 8, "end_offset" : 10, "type" : "CN_WORD", "position" : 3 }, { "token" : "是", "start_offset" : 10, "end_offset" : 11, "type" : "CN_CHAR", "position" : 4 }, { "token" : "一个", "start_offset" : 11, "end_offset" : 13, "type" : "CN_WORD", "position" : 5 }, { "token" : "重要功能", "start_offset" : 13, "end_offset" : 17, "type" : "CN_WORD", "position" : 6 } ] }
上传并启动停用词词典文件(DOC_STOPWORD.dic),然后重新执行查询命令,注意对比前后两次的查询结果。
如何上传词典文件,请参见上传 IK 分词词典文件。
{ "tokens" : [ { "token" : "云搜索服务", "start_offset" : 0, "end_offset" : 5, "type" : "CN_WORD", "position" : 0 }, { "token" : "ik", "start_offset" : 6, "end_offset" : 8, "type" : "ENGLISH", "position" : 1 }, { "token" : "分词", "start_offset" : 8, "end_offset" : 10, "type" : "CN_WORD", "position" : 2 }, { "token" : "重要功能", "start_offset" : 13, "end_offset" : 17, "type" : "CN_WORD", "position" : 3 } ] }