2016-03-01 141 views
2

我创建通过使用PUT请求名为test指数:mapper_parsing_exception自定义分析器,同时在elasticsearch中创建索引?

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。

回答

3

由于错误消息描述了自定义分析器的如my_analyzer在映射中不适用于index选项。唯一的值可以采取按documentation

no

Do not add this field value to the index. With this setting, the field will not be queryable.

not_analyzed

Add the field value to the index unchanged, as a single term. This is the default for all fields that support this option except for string fields. not_analyzed fields are usually used with term-level queries for structured search.

analyzed

This option applies only to string fields, for which it is the default. The string field value is first analyzed to convert the string into terms (e.g. a list of individual words), which are then indexed. At search time, the query string is passed through (usually) the same analyzer to generate terms in the same format as those in the index. It is this process that enables full text search.

如果你想设置自定义分析仪对现场使用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 
       } 
      } 
     } 
    } 
} 
+0

哦!好。那是一个很糟糕的错误。 谢谢! –

相关问题