简体   繁体   English

mapper_parsing_exception为自定义分析器,同时在Elasticsearch中创建索引?

[英]mapper_parsing_exception for a custom analyzer while creating index in elasticsearch?

I create an index named test via a PUT request using: 我使用以下命令通过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
                }
            }
        }
    }
}

But this returns the following error: 但这返回以下错误:

{
  "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. 我发送的json似乎有效。 What is the reason of this error? 此错误的原因是什么?

I am using ES 2.2.0. 我正在使用ES 2.2.0。

As the error message describes custom-analyzer's such as my_analyzer are not valid values for index option in mapping. 如错误消息所述,自定义分析器(例如my_analyzer不是映射中index选项的有效值。 The only values it can take as per documentation are 根据文档,它只能采用的值是

no 没有

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. not_analyzed字段通常与术语级查询一起用于结构化搜索。

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 (eg 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 如果要为字段设置自定义分析仪,请使用分析仪选项

Example: 例:

{
    "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.

相关问题 Elasticsearch批量索引“ mapper_parsing_exception” - Elasticsearch bulk index “mapper_parsing_exception” 在弹性搜索 6.4.0 中创建索引时出现 mapper_parsing_exception - mapper_parsing_exception while creating an index in elastic search 6.4.0 休眠搜索和弹性搜索:mapper_parsing_exception + 分析器 [...] 未找到字段 [...] - Hibernate search and elasticsearch: mapper_parsing_exception + analyzer [...] not found for field [...] Elasticsearch mapper_parsing_exception - Elasticsearch mapper_parsing_exception Elasticsearch 6.5.4 中的 mapper_parsing_exception - mapper_parsing_exception in Elasticsearch 6.5.4 Elasticsearch TransportError(400,'mapper_parsing_exception') - Elasticsearch TransportError(400, 'mapper_parsing_exception') mapper_parsing_exception | Elasticsearch | 全球序号 - mapper_parsing_exception | Elasticsearch | Global Ordinal Elasticsearch 同义词错误 - mapper_parsing_exception - Elasticsearch synomys error - mapper_parsing_exception Elasticsearch:升级到 7.9.3 后无法创建索引 (mapper_parsing_exception) - Elasticsearch: can't create an index after upgrade to 7.9.3 (mapper_parsing_exception) Rails __elasticsearch__.create_index! “根映射定义有不受支持的参数(mapper_parsing_exception)” - Rails __elasticsearch__.create_index! "Root mapping definition has unsupported parameters(mapper_parsing_exception)"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM