• 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])
     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])
     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"}

    插入成功:

  • 相关阅读:
    CSPS_108
    TortoiseGit配置密钥的方法
    SLF4J和Logback和Log4j和Logging的区别与联系
    slf4j log4j logback关系详解和相关用法
    dubbo服务telnet命令的使用
    基于IDEA的JavaWeb开发环境搭建
    jdk8--十大新特性
    jdk8--collect总结
    字符串的排列
    调整数组顺序使奇数位于偶数前面
  • 原文地址:https://www.cnblogs.com/houchen/p/14152556.html
Copyright © 2020-2023  润新知