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