我使用以下命令通过test
请求创建一个名为PUT
的索引:
PUT http://localhost:9250/test
{
"settings": {
"analysis": {
"char_filter": {
"&_to_and": {
"type": "mapping",
"mappings": ["& => and"]
}
},
"filter": {
"my_stopwords": {
"type": "stop",
"stopwords": ["the", "a"]
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"char_filter": ["html_strip", "&_to_and"],
"tokenizer": "standard",
"filter": ["lowercase", "my_stopwords"]
},
"folding": {
"token_filters": ["lowercase", "asciifolding"],
"tokenizer": "standard",
"type": "custom"
}
}
}
},
"mappings": {
"tweet": {
"dynamic": "strict",
"properties": {
"author": {
"type": "string",
"index": "my_analyzer",
"store": true
},
"text": {
"type": "string",
"index": "folding",
"store": true
},
"timestamp": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ssZ",
"store": true
}
}
}
}
}
但这返回以下错误:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "wrong value for index [my_analyzer] for field [author]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [tweet]: wrong value for index [my_analyzer] for field [author]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "wrong value for index [my_analyzer] for field [author]"
}
},
"status": 400
}
我发送的json似乎有效。此错误的原因是什么?
我正在使用ES 2.2.0。
最佳答案
如错误消息所述,自定义分析器(例如my_analyzer
)不是映射中index
选项的有效值。根据documentation只能取的值是
如果要为字段设置自定义分析器,请使用analyzer选项
例:
{
"settings": {
"analysis": {
"char_filter": {
"&_to_and": {
"type": "mapping",
"mappings": ["& => and"]
}
},
"filter": {
"my_stopwords": {
"type": "stop",
"stopwords": ["the", "a"]
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"char_filter": ["html_strip", "&_to_and"],
"tokenizer": "standard",
"filter": ["lowercase", "my_stopwords"]
},
"folding": {
"token_filters": ["lowercase", "asciifolding"],
"tokenizer": "standard",
"type": "custom"
}
}
}
},
"mappings": {
"tweet": {
"dynamic": "strict",
"properties": {
"author": {
"type": "string",
"analyzer": "my_analyzer",
"store": true
},
"text": {
"type": "string",
"analyzer": "folding",
"store": true
},
"timestamp": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ssZ",
"store": true
}
}
}
}
}
关于elasticsearch - mapper_parsing_exception为自定义分析器,同时在Elasticsearch中创建索引?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35731835/