ES默认提供了八种内置的analyzer,针对不同的场景可以使用不同的analyzer;
1、standard analyzer
1.1、standard类型及分词效果
在未显式指定analyzer的情况下standard analyzer为默认analyzer,其提供基于语法进行分词(基于Unicode文本分段算法)且在多数语言当中表现都不错;
//测试standard analyzer默认分词效果
//请求参数
POST _analyze
{
"analyzer": "standard",
"text": "transimission control protocol is a transport layer protocol"
}
//结果返回
{
"tokens" : [
{
"token" : "transimission",
"start_offset" : 0,
"end_offset" : 13,
"type" : "<ALPHANUM>",
"position" : 0
},
{
"token" : "control",
"start_offset" : 14,
"end_offset" : 21,
"type" : "<ALPHANUM>",
"position" : 1
},
{
"token" : "protocol",
"start_offset" : 22,
"end_offset" : 30,
"type" : "<ALPHANUM>",
"position" : 2
},
{
"token" : "is",
"start_offset" : 31,
"end_offset" : 33,
"type" : "<ALPHANUM>",
"position" : 3
},
{
"token" : "a",
"start_offset" : 34,
"end_offset" : 35,
"type" : "<ALPHANUM>",
"position" : 4
},
{
"token" : "transport",
"start_offset" : 36,
"end_offset" : 45,
"type" : "<ALPHANUM>",
"position" : 5
},
{
"token" : "layer",
"start_offset" : 46,
"end_offset" : 51,
"type" : "<ALPHANUM>",
"position" : 6
},
{
"token" : "protocol",
"start_offset" : 52,
"end_offset" : 60,
"type" : "<ALPHANUM>",
"position" : 7
}
]
}
以上句子通过分词之后得到的关键词为:
[transmission, control, protocol, is, a, transport, layer, protocol]
1.2、standard类型可配置参数
序号 | 参数 | 参数说明 |
---|---|---|
1 | max_token_length | 原始字符串拆分出的单个token所允许的最大长度,若拆分出的token查询超过最大值则按照最大值位置进行拆分,多余的作为另外的token,默认值为255; |
2 | stopwords | 预定义的停用词,可以为0个或多个,例如_english_或数组类型值,默认值为_none_; |
3 | stopwords_path | 停用词文件路径; |
以下实例配置max_token_length参数
//standard参数配置定义
PUT standard_analyzer_token_length_conf_index
{
"settings": {
"analysis": {
"analyzer": {
"english_analyzer":{
"type":"standard",
"max_token_length":5,
"stopwords":"_english_"
}
}
}
}
}
//测试standard可配置参数