0

I'm using Curl to put data into ES. I have already created a customer index. The following command is from ES document.

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

When I do this, I get an error.

{
  "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
}

I think, the below is the main reason of my error.

reason" : "Unexpected character ('n' (code 110)): was expecting double-quote to start field name

I have a feeling that I need to use (backslash) to escape. However, my attempt \' is not working great. Any advice?

Jin Lee
  • 3,194
  • 12
  • 46
  • 86

1 Answers1

2

I made it work like the below.

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 " 
}
' 

Answer without my comment:

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '
{
    \"name\": \"John Doe\"              
}
' 
Jin Lee
  • 3,194
  • 12
  • 46
  • 86
  • 2
    You can read [this question](https://stackoverflow.com/questions/34847981/curl-with-multiline-of-json) for different ways to pass json as curl body parameter – Pierre-Nicolas Mougel Jul 12 '19 at 09:27