配置内置分析器
内置分析器无需任何配置即可直接使用。不过,其中一些分析器支持通过配置选项来改变其行为。例如,可以配置 standard 分析器以支持停用词列表。
PUT my-index-000001
{
"settings": {
"analysis": {
"analyzer": {
"std_english": {
"type": "standard",
"stopwords": "_english_"
}
}
}
},
"mappings": {
"properties": {
"my_text": {
"type": "text",
"analyzer": "standard",
"fields": {
"english": {
"type": "text",
"analyzer": "std_english"
}
}
}
}
}
}
POST my-index-000001/_analyze
{
"field": "my_text",
"text": "The old brown cow"
}
POST my-index-000001/_analyze
{
"field": "my_text.english",
"text": "The old brown cow"
}
- 我们将
std_english分析器定义为基于standard分析器,但配置为移除预定义的英语停用词列表。 my_text字段直接使用standard分析器,无需任何配置。该字段不会移除任何停用词。生成的词元为:[ the, old, brown, cow ]my_text.english字段使用std_english分析器,因此会移除英语停用词。生成的词元为:[ old, brown, cow ]