AliNLP分词插件是阿里云Elasticsearch自带的一个系统默认插件。通过该插件,您可以在阿里云Elasticsearch中集成对应的分析器和分词器,完成文档分析和检索。您也可以使用AliNLP分词插件的词库配置功能,通过词典文件的热更新自定义词库配置(替换默认词典)。本文介绍如何使用AliNLP分词插件。
前提条件
如果还未安装,请先安装AliNLP分词插件。安装前需要确保实例的内存大小为4GB及以上(生产环境中要求最低为8GB)。具体安装步骤,请参见安装或卸载系统默认插件。
注意
- 5.x版本的实例不支持AliNLP分词插件。
- 如果实例的内存大小不满足要求,需要先升级。具体操作,请参见升配集群。
背景信息
- 分析器:aliws(不会截取虚词、虚词短语、符号)
- 分词器:aliws_tokenizer
您可以使用上述分析器和分词器查询文档,也可以通过词库配置功能,自定义更新分词词库。详细信息,请参见下文的查询文档和配置词库。
查询文档
配置词库
AliNLP分词插件支持词库配置,即上传自定义词典文件,替换默认词典。上传后节点能自动加载词典文件,实现词典的热更新操作(不会触发集群重启)。
测试分析器
执行如下命令,测试aliws分析器。
GET _analyze
{
"text": "I like go to school.",
"analyzer": "aliws"
}
执行成功后,返回如下结果。
{
"tokens" : [
{
"token" : "i",
"start_offset" : 0,
"end_offset" : 1,
"type" : "word",
"position" : 0
},
{
"token" : "like",
"start_offset" : 2,
"end_offset" : 6,
"type" : "word",
"position" : 2
},
{
"token" : "go",
"start_offset" : 7,
"end_offset" : 9,
"type" : "word",
"position" : 4
},
{
"token" : "school",
"start_offset" : 13,
"end_offset" : 19,
"type" : "word",
"position" : 8
}
]
}
测试分词器
执行如下命令,测试aliws_tokenizer分词器。
GET _analyze
{
"text": "I like go to school.",
"tokenizer": "aliws_tokenizer"
}
执行成功后,返回如下结果。
{
"tokens" : [
{
"token" : "I",
"start_offset" : 0,
"end_offset" : 1,
"type" : "word",
"position" : 0
},
{
"token" : " ",
"start_offset" : 1,
"end_offset" : 2,
"type" : "word",
"position" : 1
},
{
"token" : "like",
"start_offset" : 2,
"end_offset" : 6,
"type" : "word",
"position" : 2
},
{
"token" : " ",
"start_offset" : 6,
"end_offset" : 7,
"type" : "word",
"position" : 3
},
{
"token" : "go",
"start_offset" : 7,
"end_offset" : 9,
"type" : "word",
"position" : 4
},
{
"token" : " ",
"start_offset" : 9,
"end_offset" : 10,
"type" : "word",
"position" : 5
},
{
"token" : "to",
"start_offset" : 10,
"end_offset" : 12,
"type" : "word",
"position" : 6
},
{
"token" : " ",
"start_offset" : 12,
"end_offset" : 13,
"type" : "word",
"position" : 7
},
{
"token" : "school",
"start_offset" : 13,
"end_offset" : 19,
"type" : "word",
"position" : 8
},
{
"token" : ".",
"start_offset" : 19,
"end_offset" : 20,
"type" : "word",
"position" : 9
}
]
}