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

信息发布:soゝso 发布日期:2016-08-22 18:52 热度:888 分享到:

昨晚在做一个 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 [http://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 ,就解决错误了。


本文主题

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

¥我需要走的更远,点击我 赞助。 如果还有疑问,点击我加群,为你提供最好的解答。


工具导航地图

 
Nodejs + socket Demo 赞助二维码 赞助名单 百度口碑点赞 查看QQ群美女帅哥 点击加QQ群 听音乐 开启弹幕 X
反馈意见