![](/img/trans.png)
[英]Elasticsearch Error: MapperParsingException: failed to parse
[英]Elasticsearch: Failed to parse mapping [_doc]
我正在尝试为索引创建动态模板映射,但不断收到以下错误:
Invocation of init method failed; nested exception is ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [mappings : {dynamic_templates=[{articleNumber={mapping={type=text, fields={keyword={type=keyword}}}, match_mapping_type=*, match=articleNumber*}}]}]]]; nested: ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=Root mapping definition has unsupported parameters: [mappings : {dynamic_templates=[{articleNumber={mapping={type=text, fields={keyword={type=keyword}}}, match_mapping_type=*, match=articleNumber*}}]}]]];
这是我尝试创建映射的结构:
{
"mappings": {
"dynamic_templates": [
{
"articleNumber": {
"match_mapping_type": "*",
"match": "articleNumber*",
"mapping": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
]
}
}
是映射结构有误? 或者这里一切正常,我应该看看解析映射对象的方式?
更新
这是我用来创建映射的代码:
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
CreateIndexResponse createIndexResponse = getClient().indices().create(createIndexRequest.mapping(getIndexMapping()), RequestOptions.DEFAULT);
private XContentBuilder getIndexMapping() throws IOException {
String mappingObj = "{\"mappings\":{\"dynamic_templates\":[{\"articleNumber\":{\"match_mapping_type\":\"string\",\"match\":\"articleNumber*\",\"mapping\":{\"type\":\"text\",\"fields\":{\"keyword\":{\"type\":\"keyword\"}}}}}]}}";
XContentBuilder b = XContentFactory.jsonBuilder().prettyPrint();
try (XContentParser p = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY,
null, mappingObj)) {
b.copyCurrentStructure(p);
}
System.err.println(b.toString());
return b;
}
在@dhamo 对该问题的评论之后,修复方法是从
CreateIndexResponse createIndexResponse = getClient()索引()创建(createIndexRequest映射(getIndexMapping()),RequestOptions.DEFAULT)。。
到
CreateIndexResponse createIndexResponse = getClient()索引()创建(createIndexRequest源(getIndexMapping()),RequestOptions.DEFAULT)。。
CreateIndexRequests 上的旧 .mappings() 方法现在只声明索引定义的映射部分(使用 .settings() 方法单独定义设置)。 所以现在我们只使用 .source() 当我们有一个用于索引定义的 json 对象时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.