Stop 词元过滤器
stop 词元过滤器用于在分析期间从词元流中删除常用词(也称为*停用词*)。停用词通常是冠词和介词,例如 a 或 for。这些词在搜索查询中没有显著意义,通常被排除以提高搜索效率和相关性。
默认的英语停用词列表包括以下单词:a, an, and, are, as, at, be, but, by, for, if, in, into, is, it, no, not, of, on, or, such, that, the, their, then, there, these, they, this, to, was, will 和 with。
参数
stop 词元过滤器可以使用以下参数进行配置。
| 参数 | 必需/可选 | 数据类型 | 描述 |
|---|---|---|---|
停用词 | 可选 | 字符串 | 指定自定义停用词数组或语言预定义停用词集。默认值为 _english_。 |
停用词路径 | 可选 | 字符串 | 指定包含自定义停用词的文件的文件路径(绝对路径或相对于配置目录的路径)。 |
ignore_case | 可选 | 布尔型 | 如果为 true,则停用词将不区分大小写进行匹配。默认值为 false。 |
remove_trailing | 可选 | 布尔型 | 如果为 true,则在分析期间将删除尾随停用词。默认值为 true。 |
示例
以下示例请求创建一个名为 my-stopword-index 的新索引,并配置一个分析器,其中包含一个使用英语预定义停用词列表的 stop 过滤器
PUT /my-stopword-index
{
"settings": {
"analysis": {
"filter": {
"my_stop_filter": {
"type": "stop",
"stopwords": "_english_"
}
},
"analyzer": {
"my_stop_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"my_stop_filter"
]
}
}
}
}
}
生成的词元
使用以下请求检查使用该分析器生成的词元
GET /my-stopword-index/_analyze
{
"analyzer": "my_stop_analyzer",
"text": "A quick dog jumps over the turtle"
}
响应包含生成的词元
{
"tokens": [
{
"token": "quick",
"start_offset": 2,
"end_offset": 7,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "dog",
"start_offset": 8,
"end_offset": 11,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "jumps",
"start_offset": 12,
"end_offset": 17,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "over",
"start_offset": 18,
"end_offset": 22,
"type": "<ALPHANUM>",
"position": 4
},
{
"token": "turtle",
"start_offset": 27,
"end_offset": 33,
"type": "<ALPHANUM>",
"position": 6
}
]
}
按语言分类的预定义停用词集
以下是按语言分类的所有可用预定义停用词集列表
阿拉伯语亚美尼亚语巴斯克语孟加拉语_brazilian_(巴西葡萄牙语)保加利亚语加泰罗尼亚语_cjk_(中文、日文和韩文)捷克语丹麦语荷兰语英语爱沙尼亚语芬兰语法语加利西亚语德语希腊语印地语匈牙利语印度尼西亚语爱尔兰语意大利语拉脱维亚语立陶宛语挪威语波斯语葡萄牙语罗马尼亚语俄语索拉尼语西班牙语瑞典语泰语土耳其语