Link Search Menu Expand Document Documentation Menu

Stop 词元过滤器

stop 词元过滤器用于在分析期间从词元流中删除常用词(也称为*停用词*)。停用词通常是冠词和介词,例如 afor。这些词在搜索查询中没有显著意义,通常被排除以提高搜索效率和相关性。

默认的英语停用词列表包括以下单词:a, an, and, are, as, at, be, but, by, for, if, in, into, is, it, no, not, of, on, or, such, that, the, their, then, there, these, they, this, to, was, willwith

参数

stop 词元过滤器可以使用以下参数进行配置。

参数 必需/可选 数据类型 描述
停用词 可选 字符串 指定自定义停用词数组或语言预定义停用词集。默认值为 _english_
停用词路径 可选 字符串 指定包含自定义停用词的文件的文件路径(绝对路径或相对于配置目录的路径)。
ignore_case 可选 布尔型 如果为 true,则停用词将不区分大小写进行匹配。默认值为 false
remove_trailing 可选 布尔型 如果为 true,则在分析期间将删除尾随停用词。默认值为 true

示例

以下示例请求创建一个名为 my-stopword-index 的新索引,并配置一个分析器,其中包含一个使用英语预定义停用词列表的 stop 过滤器

PUT /my-stopword-index
{
  "settings": {
    "analysis": {
      "filter": {
        "my_stop_filter": {
          "type": "stop",
          "stopwords": "_english_"
        }
      },
      "analyzer": {
        "my_stop_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "my_stop_filter"
          ]
        }
      }
    }
  }
}

生成的词元

使用以下请求检查使用该分析器生成的词元

GET /my-stopword-index/_analyze
{
  "analyzer": "my_stop_analyzer",
  "text": "A quick dog jumps over the turtle"
}

响应包含生成的词元

{
  "tokens": [
    {
      "token": "quick",
      "start_offset": 2,
      "end_offset": 7,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "dog",
      "start_offset": 8,
      "end_offset": 11,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "jumps",
      "start_offset": 12,
      "end_offset": 17,
      "type": "<ALPHANUM>",
      "position": 3
    },
    {
      "token": "over",
      "start_offset": 18,
      "end_offset": 22,
      "type": "<ALPHANUM>",
      "position": 4
    },
    {
      "token": "turtle",
      "start_offset": 27,
      "end_offset": 33,
      "type": "<ALPHANUM>",
      "position": 6
    }
  ]
}

按语言分类的预定义停用词集

以下是按语言分类的所有可用预定义停用词集列表

剩余 350 字符

有问题?

想要贡献?