elasticsearch 使用Curl将数据放入ES并获得意外字符(';n';(代码110)),elasticsearch,curl,elasticsearch,Curl" /> elasticsearch 使用Curl将数据放入ES并获得意外字符(';n';(代码110)),elasticsearch,curl,elasticsearch,Curl" />

elasticsearch 使用Curl将数据放入ES并获得意外字符(';n';(代码110))

elasticsearch 使用Curl将数据放入ES并获得意外字符(';n';(代码110)),elasticsearch,curl,elasticsearch,Curl,我用Curl把数据放到ES中。我已经创建了一个customer索引。 以下命令来自 当我这样做时,我会得到一个错误 { "error" : { "root_cause" : [ { "type" : "mapper_parsing_exception", "reason" : "failed to parse" } ], "type" : "mapper_parsing_exception", "reas

我用Curl把数据放到ES中。我已经创建了一个
customer
索引。 以下命令来自

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

{
  "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
}
我认为,以下是我错误的主要原因

原因“:“意外字符('n'(代码110)):应以双引号开始字段名


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

我让它像下面那样工作

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 " 
}
' 
您可以了解将json作为curl body参数传递的不同方式
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\"              
}
'