ElasticSearch _bulk批量插入报错


一、现象

今天在 ElasticSearch 批量插入时:

POST /customer/external/_bulk
{
  "index":{"_id":"1"}
}
{
  "name":"John"
}
{
  "index":{"_id":"2"}
}
{
  "name":"tom"
}

出现了这样的错误:

{
  "error": {
    "root_cause": [
      {
        "type": "json_e_o_f_exception",
        "reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2eeea373; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2eeea373; line: 1, column: 3]"
      }
    ],
    "type": "json_e_o_f_exception",
    "reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2eeea373; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2eeea373; line: 1, column: 3]"
  },
  "status": 500
}

 

二、原因

bulk api对json语法有严格的要求,每个json串不能换行,只能放到一行,同时一个json串和一个json串之间必须要换行,否则会出现如上错误

 

三、解决

POST /customer/external/_bulk
{"index":{"_id":"1"}}
{"name":"John"}
{"index":{"_id":"2"}}
{"name":"tom"}

插入成功:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM