语言分析器
OpenSearch 支持以下语言分析器:arabic、armenian、basque、bengali、brazilian、bulgarian、catalan、czech、danish、dutch、english、estonian、finnish、french、galician、german、greek、hindi、hungarian、indonesian、irish、italian、latvian、lithuanian、norwegian、persian、portuguese、romanian、russian、sorani、spanish、swedish、thai 和 turkish。
要在映射索引时使用分析器,请在查询中指定值。例如,要使用法语分析器映射您的索引,请在分析器字段中指定 french 值。
"analyzer": "french"
请求示例
以下查询指定了一个索引 my-index,其中 content 字段配置为多字段,一个名为 french 的子字段配置为 french 语言分析器。
PUT my-index
{
"mappings": {
"properties": {
"content": {
"type": "text",
"fields": {
"french": {
"type": "text",
"analyzer": "french"
}
}
}
}
}
}
默认的 french 分析器也可以使用以下查询为整个索引配置。
PUT my-index
{
"settings": {
"analysis": {
"analyzer": {
"default": {
"type": "french"
}
}
}
},
"mappings": {
"properties": {
"content": {
"type": "text"
},
"title": {
"type": "text"
},
"description": {
"type": "text"
}
}
}
}
词干排除
您可以通过提供应从词干提取中排除的小写单词列表,将词干排除应用于任何语言分析器。在内部,OpenSearch 使用 keyword_marker 词元过滤器将这些单词标记为关键字,确保它们不进行词干提取。
词干排除示例
使用以下请求配置 stem_exclusion
PUT index_with_stem_exclusion_english_analyzer
{
"settings": {
"analysis": {
"analyzer": {
"stem_exclusion_english_analyzer":{
"type":"english",
"stem_exclusion": ["manager", "management"]
}
}
}
}
}
自定义分析器中的词干排除
所有语言分析器都由特定语言的分词器和词元过滤器组成。如果您想实现一个带有词干排除功能的自定义语言分析器版本,您需要配置 keyword_marker 词元过滤器,并在 keywords 参数中列出要从词干提取中排除的单词。
PUT index_with_keyword_marker_analyzer
{
"settings": {
"analysis": {
"filter": {
"protected_keywords_filter": {
"type": "keyword_marker",
"keywords": ["Apple", "OpenSearch"]
}
},
"analyzer": {
"custom_english_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"protected_keywords_filter",
"english_stemmer"
]
}
}
}
}
}