【问题标题】:Define a stop wordlist into an analyser with elasticsearch使用 elasticsearch 将停止词表定义到分析器中
【发布时间】:2016-09-25 03:31:20
【问题描述】:

我正在尝试将停用词列表添加到我的映射中,但出现错误。这是映射:

PUT test-recipe
{
  "mappings": {
    "recipe" : {
      "properties" : {
        "ingredients" : {
          "type" :    "string",
          "analyzer": "english",
          "stopwords": ["my", "stop", "words"]
        }
      }
    }
  }
}

这个映射在没有停用词参数的情况下可以正常工作。但是在停用词字段中,我收到以下错误:

{
   "error": {
      "root_cause": [
         {
            "type": "mapper_parsing_exception",
            "reason": "Mapping definition for [ingredients] has unsupported parameters:  [stopwords : [Best®, Halves, organic, island, free, gluten, high-gluten, segments, baking, cooking, new, active, dry, leaves, slices, sliced, warm, root, hot, jack, extract, slivered, sliver, non-fat, fat, chopped, skinless, seed, nonfat, melted, cracked, in, split, vegetable, smoked, medium, nectar, all-purpose, fraîche, fresh]]"
         }
      ],
      "type": "mapper_parsing_exception",
      "reason": "Failed to parse mapping [recipe]: Mapping definition for [ingredients] has unsupported parameters:  [stopwords : [Best®, Halves, organic, island, free, gluten, high-gluten, segments, baking, cooking, new, active, dry, leaves, slices, sliced, warm, root, hot, jack, extract, slivered, sliver, non-fat, fat, chopped, skinless, seed, nonfat, melted, cracked, in, split, vegetable, smoked, medium, nectar, all-purpose, fraîche, fresh]]",
      "caused_by": {
         "type": "mapper_parsing_exception",
         "reason": "Mapping definition for [ingredients] has unsupported parameters:  [stopwords : [Best®, Halves, organic, island, free, gluten, high-gluten, segments, baking, cooking, new, active, dry, leaves, slices, sliced, warm, root, hot, jack, extract, slivered, sliver, non-fat, fat, chopped, skinless, seed, nonfat, melted, cracked, in, split, vegetable, smoked, medium, nectar, all-purpose, fraîche, fresh]]"
      }
   },
   "status": 400
}

如果你能告诉我为什么我会遇到这个问题,那会让我很开心。此外,在执行“更像这个查询”时,是否会考虑停用词列表?

【问题讨论】:

    标签: elasticsearch mapping stop-words


    【解决方案1】:

    您必须为停用词创建过滤器并在分析器中使用它

    #remove index
    #DELETE recipe
    
    #put mapping, analyzer and filter for stop words
    PUT recipe
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "cooking_nonstop": {
              "type": "custom",
              "tokenizer": "standard",
              "filter": [
                "lowercase",
                "english_morphology",
                "my_stopwords"
              ]
            }
            },
            "filter": {
              "my_stopwords": {
                "type": "stop",
                "stopwords": "Best®,Halves,organic,island,free,gluten,high-gluten,segments,baking,cooking,new,active,dry,leaves,slices,sliced,warm,root,hot,jack,extract,slivered,sliver,non-fat,fat,chopped,skinless,seed,nonfat,melted,cracked,in,split,vegetable,smoked,medium,nectar,all-purpose,fraîche,fresh"
              }
            }
          }
        },
        "mappings": {
          "recipe": {
            "properties": {
              "ingredients": {
                "type": "string",
                "analyzer": "cooking_nonstop"
              }
            }
          }
        }
      }
    
    #check analyzer
    GET /recipe/_analyze?analyzer=cooking_nonstop&text=put+fresh+egs+in+hot+water
    
    #create document
    POST recipe/recipe/boiled_egs
    {
      "ingredients":"put fresh egs in hot water"
    }
    
    #another stop word filter demonstration
    POST recipe/_search
    {
      "aggs": {
        "terms": {
          "terms": {
            "field": "ingredients",
            "size": 10
          }
        }
      }
    }
    

    【讨论】:

    • 我收到以下错误:自定义分析器 [cooking_nonstop] 未能在名称 [english_morphology] 下找到过滤器
    • 没错,只需将其从“cooking_nonstop”分析器中删除,或从here 安装即可。我是复制/粘贴问题 =)
    猜你喜欢
    • 1970-01-01
    • 2022-10-08
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 2021-07-04
    相关资源
    最近更新 更多