一. 内置分析器(analyzer)
内置分析器无需任何配置即可直接使用,也支持配置选项来更改其行为。
下面示例,分别使用了自定义分析器与内置分析器
PUT my-index-000001
{
"settings": {
"analysis": {
"analyzer": {
"std_english": { #自定义分析器名为std_english
"type": "standard", #使用standard分词器
"stopwords": "_english_" #使用停用词
}
}
}
},
"mappings": {
"properties": {
"my_text": { #创建一个字段
"type": "text",
"analyzer": "standard", #使用内置standard分析器
"fields": {
"english": { #创建子字段名为english
"type": "text",
"analyzer": "std_english" #使用自定义std_english分析器
}
}
}
}
}
}
1.1 下面使用standard分析器
POST my-index-000001/_analyze
{
"field": "my_text",
"text": "The old brown cow"
}
分析结果:[ the, old, brown,cow]
1.2 下面使用自定义std_english分析器
POST my-index-000001/_analyze
{
"field": "my_text.english", #调用子字段方式
"text": "The old brown cow"
}
分析结果: [old, brown,cow]
使用自定义的std_english分析器,会发现少了一个词 the, 这是因为自定义的分析器中配置了stopwords停用词。