自定义分词器

系统管理员 2023-06-20 10:53 141阅读 0赞

自定义分析器地址:https://www.elastic.co/guide/cn/elasticsearch/guide/cn/custom-analyzers.html

PUT /my_index
{
“settings”: {
“analysis”: {
“char_filter”: { … custom character filters … },//字符过滤器
“tokenizer”: { … custom tokenizers … },//分词器
“filter”: { … custom token filters … }, //词单元过滤器
“analyzer”: { … custom analyzers … }
}
}
}
============================实例===========================
PUT /my_index
{
“settings”: {
“analysis”: {
“char_filter”: {
“&_to_and”: {
“type”: “mapping”,
“mappings”: [ “&=> and “]
}},
“filter”: {
“my_stopwords”: {
“type”: “stop”,
“stopwords”: [ “the”, “a” ]
}},
“analyzer”: {
“my_analyzer”: {
“type”: “custom”,
“char_filter”: [ “html_strip”, “&_to_and” ],
“tokenizer”: “standard”,
“filter”: [ “lowercase”, “my_stopwords” ]
}}
}}}

============================实例===========================
比如自定义好的analyzer名字是my_analyzer,在此索引下的某个新增字段应用此分析器
PUT /my_index/_mapping
{
“properties”:{
“username”:{
“type”:”text”,
“analyzer” : “my_analyzer”
},
“password” : {
“type” : “text”
}

}
}
=================插入数据====================
PUT /my_index/_doc/1
{
“username”:”The quick & brown fox “,
“password”:”The quick & brown fox “

}
====username采用自定义分析器my_analyzer,password采用默认的standard分析器==
===验证
GET /index_v1/_analyze
{
“field”:”username”,
“text”:”The quick & brown fox”
}

GET /index_v1/_analyze
{
“field”:”password”,
“text”:”The quick & brown fox”
}

发表评论

表情:
评论列表 (有 0 条评论,141人围观)

还没有评论,来说两句吧...

相关阅读

    相关 es定义分词

    es自带了一些分词器,即在默认情况下,如果不对自己创建的索引做任何的设置和修改,es会按照standard进行分词,怎么看我们自己创建的分词的相关设置和属性呢?首先看下面的一个