Elasticsearch 配置内置分析器(3)

一. 内置分析器(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停用词。

 

参考官方资料:Configuring built-in analyzers

 

posted on   花阴偷移  阅读(43)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
历史上的今天:
2019-04-09 asp.net core系列 51 Identity 授权(下)

导航

点击右上角即可分享
微信分享提示