首页 > 解决方案 > 如何从弹性搜索中的默认_english_停用词列表中删除停用词?

问题描述

我正在使用默认的英语停用词过滤文本。我发现'and'是英文的停用词,但我需要搜索包含'and'的结果。我只想and从这个默认的英语停用词过滤器中删除单词并像往常一样使用其他停用词。我的 elasticsearch 架构如下所示。

"settings": {
    "analysis": {
      "analyzer": {
        "default": {
          "tokenizer": "whitespace" ,
          "filter": ["stop_english"]
        } 
       }....,
       "filter":{
         "stop_english": {
            "type": "stop",
            "stopwords": "_english_"
        }
}

我希望看到包含AND带有 _search api 的单词的文档。

标签: elasticsearchstop-words

解决方案


您可以像这样手动设置给定索引的停用词:

PUT /my_index
{
    "settings": {
        "analysis": {
            "filter": {
                "my_stop": {
                    "type":       "stop",
                    "stopwords": ["and", "is", "the"]
                }
            }
        }
    }
}

我还在这里找到了 elasticsearch 使用的英语停用词列表。如果您设法在索引中手动设置相同的停用词列表减去“and”,并在新配置的索引中使用良好的停用词重新索引您的数据,那么您应该很高兴!

关于数据的重新索引,您应该查看reindex api。我认为这是必需的,因为数据的标记化发生在摄取时,因此您需要通过重新索引来重做摄取。在更改索引设置或某些映射更改时需要大部分时间(不是 100% 肯定,但我认为这是有道理的)。


推荐阅读