我通过 PUT 请求使用以下命令创建一个名为 test 的索引:
I create an index named test via a PUT request using:
PUT 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 }我发送的似乎是有效的。这个错误的原因是什么?
The json that I am sending seems to be valid. What is the reason of this error?
我正在使用ES 2.2.0。
I am using ES 2.2.0.
推荐答案由于错误消息描述了自定义分析器,例如 my_analyzer 不是 index 选项的有效值在映射。根据文档可以采取的唯一值是
As the error message describes custom-analyzer's such as my_analyzer are not valid values for indexoption in mapping. The only values it can take as per documentation are
否
不要添加此字段值到索引。使用此设置,字段将无法查询。
Do not add this field value to the index. With this setting, the field will not be queryable.
not_analyzed
将字段值添加到索引不变,作为单个术语。对于支持此选项的所有字段,除了字符串字段之外,这是的默认值。 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.
分析
此选项仅适用于字符串字段,它是默认值。首先分析字符串字段值,以将字符串转换为条件(例如,单个字词的列表),然后编入索引。在搜索时间,查询字符串通过(通常)在相同的分析器中生成与索引中相同格式的条款。正是这个过程启用全文搜索。
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.
如果您想为某个字段设置自定义分析器,请使用分析仪选项
If you wanted to set a custom-analyzer for a field use the analyzer option
示例:
{ "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 } } } } }更多推荐
在弹性搜索中创建索引时,自定义分析器的mapper
发布评论