ES8.13 _bulk报错Malformed content, found extra data after parsing: START_OBJECT解决

在使用elaticsearch8.13.0使用批量创建索引时,根据谷粒中说的es7.9方法去批量操作请求:

http://127.0.0.1:9200/shop/_doc/_bulk

**注意1:**设置header为Content-Type:application/x-ndjson,否则请求报错:

javascript 复制代码
{
    "error": "Content-Type header [] is not supported",
    "status": 406
}

body:

javascript 复制代码
{"index": {"_index":"shop","_type":"_doc","_id": "2004"}} 
{"id": "2004", "nickname": "index2004"} 
{"index": {"_index":"shop","_type":"_doc","_id": "2007"}} 
{"id": "2007", "nickname": "name2007"} 
{"index": {"_index":"shop","_type":"_doc","_id": "2008"}} 
{"id": "2008", "nickname": "name2008"}

报错信息如下:

javascript 复制代码
{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Malformed content, found extra data after parsing: START_OBJECT"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Malformed content, found extra data after parsing: START_OBJECT"
    },
    "status": 400
}

根据报错翻译:内容格式错误,解析后发现额外数据:START_OBJECT。其实说白了就是请求的url不对。大家可以参考elaticsearch官网查看:

Bulk API | Elasticsearch Guide [8.14] | Elastic

注意2: body里面的Json或text最后要多空一行,如下截图:

否则会报错:

javascript 复制代码
{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "The bulk request must be terminated by a newline [\\n]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "The bulk request must be terminated by a newline [\\n]"
    },
    "status": 400
}

当你把上面的2个注意项设置后,请求成功界面如下:

相关推荐
极限实验室5 小时前
搜索百科(1):Lucene —— 打开现代搜索世界的第一扇门
搜索引擎·lucene
阿里云大数据AI技术11 小时前
StarRocks 助力数禾科技构建实时数仓:从数据孤岛到智能决策
大数据
Lx35215 小时前
Hadoop数据处理优化:减少Shuffle阶段的性能损耗
大数据·hadoop
Elasticsearch19 小时前
平衡尺度:利用权重使倒数排序融合 (RRF) 更加智能
elasticsearch
武子康20 小时前
大数据-99 Spark Streaming 数据源全面总结:原理、应用 文件流、Socket、RDD队列流
大数据·后端·spark
阿里云大数据AI技术1 天前
大数据公有云市场第一,阿里云占比47%!
大数据
Lx3522 天前
Hadoop容错机制深度解析:保障作业稳定运行
大数据·hadoop
muyun28002 天前
Docker 下部署 Elasticsearch 8 并集成 Kibana 和 IK 分词器
elasticsearch·docker·容器
T06205142 天前
工具变量-5G试点城市DID数据(2014-2025年
大数据
向往鹰的翱翔2 天前
BKY莱德因:5大黑科技逆转时光
大数据·人工智能·科技·生活·健康医疗