使用 elasticsearch 将停用词表定义到分析器中
Define a stop wordlist into an analyser with elasticsearch
我正在尝试将停用词列表添加到我的映射中,但出现错误。这是映射:
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
}
如果你能告诉我为什么我会遇到这个问题,那会让我很开心。此外,在执行我的 "more like this query"?
时是否会考虑停用词列表
您必须为停用词创建过滤器并在您的分析器中使用它
#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
}
}
}
}
我正在尝试将停用词列表添加到我的映射中,但出现错误。这是映射:
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
}
如果你能告诉我为什么我会遇到这个问题,那会让我很开心。此外,在执行我的 "more like this query"?
时是否会考虑停用词列表您必须为停用词创建过滤器并在您的分析器中使用它
#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
}
}
}
}