【问题标题】:Using Curl to put data into ES and got Unexpected character ('n' (code 110))使用 Curl 将数据放入 ES 并得到 Unexpected character ('n' (code 110))
【发布时间】:2019-11-21 21:06:35
【问题描述】:

我正在使用 Curl 将数据放入 ES。我已经创建了一个customer 索引。 以下命令来自ES document

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "John Doe"
}
'

当我这样做时,我得到一个错误。

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "failed to parse"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "failed to parse",
    "caused_by" : {
      "type" : "json_parse_exception",
      "reason" : "Unexpected character ('n' (code 110)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@1ec5236e; line: 3, column: 4]"
    }
  },
  "status" : 400
}

我认为,以下是我错误的主要原因。

reason" : "意外字符 ('n' (code 110)): 期望用双引号来开始字段名称

我有一种感觉,我需要使用(反斜杠)来逃避。但是,我的尝试 \' 效果不佳。有什么建议吗?

【问题讨论】:

    标签: elasticsearch curl


    【解决方案1】:

    我让它像下面这样工作。

    curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '
    {
        \"name\": \"John Doe\"             <====  I used "backslash"  in front of all the " 
    }
    ' 
    

    没有我的评论回答:

    curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '
    {
        \"name\": \"John Doe\"              
    }
    ' 
    

    【讨论】:

    • 您可以阅读this question了解将json作为curl body参数传递的不同方式
    猜你喜欢
    • 1970-01-01
    • 2019-08-07
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多