You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ElasticSearch Bulk导入失败:parse_exception错误排查求助

问题分析与解决方法

错误原因

  1. 请求方法错误:Elasticsearch的_bulk接口需使用POST请求,你误用了PUT,导致Elasticsearch误将请求解析为创建索引操作,进而无法识别create关键字。
  2. 批量数据格式不合法:
    • Elasticsearch bulk要求每行一个独立JSON对象,不能将操作元数据(如create语句)和文档数据放在同一行。
    • 你的JSON文件中包含多余的和>符号,破坏了JSON结构。
    • 部分JSON未正确换行,导致解析失败。

解决步骤

1. 修正请求命令

将PUT改为POST,同时推荐使用application/x-ndjson作为Content-Type(适配换行分隔的JSON格式):

curl --location --request POST '127.0.0.1:9200/_bulk' \
--header 'Content-Type: application/x-ndjson' \
--data '@/Users/themis/Downloads/ml-latest-small/movies.json'

2. 修正JSON文件格式

清理多余符号,确保每行一个JSON对象,修正后的movies.json内容如下:

{ "create" : { "_index" : "movies", "_id" : "135569" } }
{ "id": "135569", "title" : "Star Trek Beyond", "year":2016 , "genre":["Action", "Adventure", "Sci-Fi"] }
{ "create" : { "_index" : "movies", "_id" : "122886" } }
{ "id": "122886", "title" : "Star Wars: Episode VII - The Force Awakens", "year":2015 , "genre":["Action", "Adventure", "Fantasy", "Sci-Fi", "IMAX"] }
{ "create" : { "_index" : "movies", "_id" : "109487" } }
{ "id": "109487", "title" : "Interstellar", "year":2014 , "genre":["Sci-Fi", "IMAX"] }
{ "create" : { "_index" : "movies", "_id" : "58559" } }
{ "id": "58559", "title" : "Dark Knight, The", "year":2008 , "genre":["Action", "Crime", "Drama", "IMAX"] }
{ "create" : { "_index" : "movies", "_id" : "1924" } }
{ "id": "1924", "title" : "Plan 9 from Outer Space", "year":1959 , "genre":["Horror", "Sci-Fi"] }

3. Postman配置调整

如果你用Postman操作:

  • 选择POST请求方法
  • URL填入http://127.0.0.1:9200/_bulk
  • Headers添加Content-Type: application/x-ndjson
  • Body选择raw并粘贴修正后的JSON内容,或选择form-data上传修正后的文件

内容的提问来源于stack exchange,提问作者Jack Daniel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 09:55:13