Elasticsearch 添加失败 MapperParsingException[object mapping for [] tried to parse field [null] as object, but found a concrete value

JSON 2016-08-22 18:52:41 69296

昨晚在做一个 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

转载时必须以链接形式注明原始出处及本声明。

本文主题:

如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。

关于作者
一个低调而闷骚的男人。
相关文章
Elasticsearch教程(五) elasticsearch Mapping的创建
Elasticsearch教程,Elasticsearch Java API创建Mapping,指定分词器
Elasticsearch教程 ,Elasticsearch count 查询,Elasticsearch 查询是否存在
Elasticsearch教程,Elasticsearch配置文件 — elasticsearch.yml
Elasticsearch教程(六) elasticsearch Client创建
网站页面添加 Google AdSense 后页面加载慢?
Elasticsearch 教程,Elasticsearch 日期查询详解,Elasticsearch Date 查询Java API
Elasticsearch教程(九) elasticsearch 查询数据 | 分页查询
Elasticsearch教程(四) elasticsearch head 插件安装和使用
Elasticsearch 分词,Elasticsearch Java API 分词 操作
最新文章
PHP if/else/elseif 语句 63
HTML5 Canvas弧线教程 52
Java赋值运算符 118
XML内部实体和外部实体 201
Java面向对象编程概念 177
PHP回显语句 127
Linux—文件树 135
C语言while循环和do while循环 150
Python元组剖析 209
MySQL触发器教程 342
最热文章
最新MyEclipse8.5注册码,有效期到2020年 (已经更新) 682607
苹果电脑Mac怎么恢复出厂系统?苹果系统怎么重装系统? 674741
免费天气API,全国天气 JSON API接口,可以获取五天的天气预报 602688
免费天气API,天气JSON API,不限次数获取十五天的天气预报 579671
Jackson 时间格式化,时间注解 @JsonFormat 用法、时差问题说明 553093
我为什么要选择RabbitMQ ,RabbitMQ简介,各种MQ选型对比 509458
Elasticsearch教程(四) elasticsearch head 插件安装和使用 480074
Jackson 美化输出JSON,优雅的输出JSON数据,格式化输出JSON数据... ... 264851
Java 信任所有SSL证书,HTTPS请求抛错,忽略证书请求完美解决 244332
Elasticsearch教程(一),全程直播(小白级别) 225657
支付扫码

所有赞助/开支都讲公开明细,用于网站维护:赞助名单查看

查看我的收藏

正在加载... ...