Elasticsearch 添加失败 MapperParsingException[object mapping for [] tried to parse field [null] as object, but found a concrete value
- Elasticsearch教程(一),全程直播(小白级别)
- Elasticsearch教程(二),IK分词器安装
- Elasticsearch教程(三),IK分词器安装 (极速版)
- Elasticsearch安装(四), elasticsearch head 插件安装和使用。
- Elasticsearch教程(五) elasticsearch Mapping的创建
- Elasticsearch教程(六) elasticsearch Client创建
- Elasticsearch教程(七) elasticsearch Insert 插入数据(Java)
- Elasticsearch教程(八) elasticsearch delete 删除数据(Java)
- Elasticsearch教程(九) elasticsearch 查询数据 | 分页查询
- Elasticsearch权威指南-中文.pdf
昨晚在做一个 Elasticsearch Demo 的时候,发现了这个错误,纠结了一小会,我的 Demo 是爬虫随便爬取了一些网站的信息,然后通过 Elasticsearch 去存储,结果发现其中一个字段,Mapping定义的类型是objcet,因为是个Array,而 Mapping 又定义不了Array
,所以定义了一个object
类型。结果创建 Mapping 成功了,但是添加数据失败了。
更多的Elasticsearch ,请点击这里: Elasticsearch教程 ,本博客主要针对2.0
以上的 Elasticsearch 版本相关使用,以Java API
为主,适用于初级 Elasticsearch 使用者参考。如果有问题可以加群一起讨论。
下面关于:
failure in bulk execution:
Elasticsearch 添加失败 MapperParsingException[object mapping for [] tried to parse field [null] as object, but found a concrete value
错误的排查的过程和结果。
我的 Mapping :
{
"mappings": {
"site_type1": {
"_ttl": {
"enabled": false
},
"properties": {
"server_address": {
"index": "not_analyzed",
"type": "string"
},
"baidu_suoyin": {
"type": "long"
},
"baidu_keys": {
"type": "long"
},
"beian_title": {
"index": "not_analyzed",
"type": "string"
},
"domain_server": {
"index": "not_analyzed",
"type": "string"
},
"domain_service": {
"index": "not_analyzed",
"type": "string"
},
"beian_index": {
"index": "not_analyzed",
"type": "string"
},
"br": {
"type": "long"
},
"city": {
"type": "object"
},
"qihu_shoulu": {
"type": "long"
},
"title": {
"type": "string"
},
"baidu_fanlian": {
"type": "long"
},
"baidu_pv": {
"type": "long"
},
"beian_type": {
"index": "not_analyzed",
"type": "string"
},
"server_ip": {
"type": "string"
},
"description": {
"type": "string"
},
"province": {
"type": "object"
},
"domain": {
"index": "not_analyzed",
"type": "string"
},
"sougou_fanlian": {
"type": "long"
},
"beian_number_no": {
"index": "not_analyzed",
"type": "string"
},
"beian_number": {
"index": "not_analyzed",
"type": "string"
},
"tags": {
"type": "object"
},
"qihu_fanlian": {
"type": "long"
},
"keywords": {
"type": "string"
},
"beian_name": {
"index": "not_analyzed",
"type": "string"
},
"baidu_shoulu": {
"type": "long"
},
"sr": {
"type": "long"
},
"alexa_pv": {
"type": "long"
},
"image": {
"type": "object"
},
"domain_begin_date": {
"index": "not_analyzed",
"type": "string"
},
"baidu_yue_shoulu": {
"type": "long"
},
"sougou_shoulu": {
"type": "long"
},
"url": {
"index": "not_analyzed",
"type": "string"
},
"server_type": {
"index": "not_analyzed",
"type": "string"
},
"server_timeout": {
"type": "long"
},
"google_fanlian": {
"type": "long"
},
"google_shoulu": {
"type": "long"
},
"update_time": {
"format": "strict_date_optional_time||epoch_millis",
"type": "date"
},
"domain_end_date": {
"index": "not_analyzed",
"type": "string"
},
"alexa_top": {
"type": "long"
},
"site_type": {
"type": "object"
},
"server_html_type": {
"index": "not_analyzed",
"type": "string"
},
"pr": {
"type": "long"
},
"baidu_zhou_shoulu": {
"type": "long"
}
}
}
}
}
添加数据的时候报错:
failure in bulk execution:
[0]: index [site_index1], type [site_type1], id [https://www.sojson.com], message [MapperParsingException[object mapping for [image] tried to parse field [null] as object, but found a concrete value]]
已经说的很清楚了,就是Mapping
和存储的数据类型对不上。
"image": {
"type": "object"
}
我开始排查存储的值有没有null
值,发现没有,都是有值了。
其实当报这样的错。有一个最简单的排查方式,就是不创建mapping
,然后直接创建索引,你看看自适应的mapping
,这个field
是什么类型。那么你创建就是什么类型。
我用自适应类型,发现这个数组的是string
类型,那么我就把它定义为string
,就解决错误了。
版权所属:SO JSON在线解析
原文地址:https://www.sojson.com/blog/128.html
转载时必须以链接形式注明原始出处及本声明。
如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。