【ElasticSearch】踩坑 关于bulk操作报错

【ElasticSearch】踩坑 关于bulk操作报错


1.问题

想要执行批量插入操作

POST /customer/external/_bulk
{"create":{"_id":"1"}}
{
  "key_id":"url_https_18560751222",
  "nodealias": "baidu",
  "taskFinishTime":"1630857697326",
  "result":
    {
      "http_request":
      {
        "responseTime":89.0
      }
    }
}
{"create":{"_id":"2"}}
{
  "key_id":"url_https_18560751211",
  "nodealias": "bing",
  "taskFinishTime":"1630857697300",
  "result":
  {
    "http_request":
    {
      "responseTime":109.0
    }
  }
}

报错:

json_e_o_f_exception

"Unexpected end-of-input: expected close marker for Object (start marker at [Source: (ByteArrayInputStream); line: 1, column: 1])\n at [Source: (ByteArrayInputStream); line: 1, column: 2]"

【ElasticSearch】踩坑 关于bulk操作报错

或者

illegal_argument_exception

Malformed action/metadata line [3], expected START_OBJECT but found [VALUE_STRING]

【ElasticSearch】踩坑 关于bulk操作报错


2.正确写法

万万没想到,_bulk的操作,行为和请求体数据 都是不能换行的。。

POST /customer/external/_bulk
{"create":{"_id":"1"}}
{"key_id":"url_https_18560751222","nodealias": "baidu","taskFinishTime":"1630857697326","result":{"http_request":{"responseTime":89.0}}}
{"create":{"_id":"2"}}
{"key_id":"url_https_18560751211","nodealias": "bing","taskFinishTime":"1630857697300","result":{"http_request":{"responseTime":109.0}}}

创建成功

【ElasticSearch】踩坑 关于bulk操作报错

上一篇:MongoDB


下一篇:MSSQL BULK INSERT 插入文本内容到数据库