[英]mapper_parsing_exception for a custom analyzer while creating index in elasticsearch?
我使用以下命令通過PUT
請求創建一個名為test
的索引:
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
選項的有效值。 根據文檔,它只能采用的值是
沒有
不要將此字段值添加到索引中。 使用此設置,該字段將不可查詢。
not_analyzed
將字段值不變地添加到索引中,作為一個術語。 這是所有支持此選項的字段(字符串字段除外)的默認設置。 not_analyzed字段通常與術語級查詢一起用於結構化搜索。
分析
此選項僅適用於字符串字段,這是默認設置。 首先分析字符串字段值,以將字符串轉換為術語(例如,單個單詞的列表),然后對其進行索引。 在搜索時,查詢字符串(通常)通過同一分析器傳遞,以生成與索引中的格式相同的術語。 正是這個過程使全文搜索成為可能。
如果要為字段設置自定義分析儀,請使用分析儀選項
例:
{
"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
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.