Unable to create document within an index

I am using command prompt on Windows 10 and trying to create a document in an index however, getting an error. Tried double quotes and single quotes however, still getting the same error. Kindly assist.

curl -XPUT "http://localhost:9200/products/mobiles/1" -d"
{
""name"":""iPhone7"",
""camera"":""12MP"",
"year": 1972
}"

error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"json_e_o_f_exception","reason":"Unexpected end-of-input in field name\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@26151b7a; line: 1, column: 355]"}},"status":400}curl: (3) Port number ended with 'M'
curl: (6) Could not resolve host: year
curl: (6) Could not resolve host: 1972
curl: (3) [globbing] unmatched close brace/bracket in column 1

Why you use ""name""?

You should try this:

curl -XPUT "http://localhost:9200/products/mobiles/1" -d'
{
"name": "iPhone7",
"camera": "12MP",
"year": 1972
}'

Hope it helps.

I tried that too. However, I get the below error -
curl -XPUT "http://localhost:9200/products/mobiles/1" -d' {
"name": "iPhone7",
"camera": "12MP",
"year": 1972
}'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: name
curl: (6) Could not resolve host: iPhone7,
curl: (6) Could not resolve host: camera
curl: (6) Could not resolve host: 12MP,
curl: (6) Could not resolve host: year
curl: (6) Could not resolve host: 1972
curl: (3) [globbing] unmatched close brace/bracket in column 1

Kindly help. Unable to understand the issue.

You need to specify the content type.

See basic examples at

I tried with content-type. I am still getting error for both cases (with single quotes & with double quotes). I am missing some information for sure.

Case 1(With single quotes)

curl -XPUT 'http://localhost:9200/products/mobiles/1' -H 'Content-Type: application/json' -d "{"name": "iPhone7", "camera": "12MP", "storage": "256GB", "display": "4.7inch", "battery": "1,960mAh", "reviews": ["Incredibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"]}"
curl: (1) Protocol "'http" not supported or disabled in libcurl
curl: (6) Could not resolve host: application
curl: (3) [globbing] bad range specification in column 106

Case 2 (With double quotes, with escape sequence)

curl -XPUT "http://localhost:9200/products/mobiles/1" -H "Content-Type: application/json" -d "{"name": "iPhone7", "camera": "12MP", "storage": "256GB", "display": "4.7inch", "battery": "1,960mAh", "reviews": ["Incredibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"]}"
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"json_e_o_f_exception","reason":"Unexpected end-of-input in field name\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@33fb2031; line: 1, column: 15]"}},"status":400}curl: (3) [globbing] bad range specification in column 106

Case 3 (With double quotes without " \ " - backslash escape sequence)

curl -XPUT "http://localhost:9200/products/mobiles/1" -H "Content-Type: application/json" -d "{"name": "iPhone7","camera": "12MP","storage": "256GB","display": "4.7inch","battery": "1,960mAh","reviews": ["Increadibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"] }"
{"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@7d3f6505; line: 1, column: 3]"}},"status":400}curl: (6) Could not resolve host: happy
curl: (6) Could not resolve host: after
curl: (6) Could not resolve host: having
curl: (6) Could not resolve host: used
curl: (6) Could not resolve host: it
curl: (6) Could not resolve host: for
curl: (6) Could not resolve host: one
curl: (6) Could not resolve host: week, Best
curl: (6) Could not resolve host: iPhone
curl: (6) Could not resolve host: so
curl: (6) Could not resolve host: far, Very
curl: (6) Could not resolve host: expensive,
curl: (6) Could not resolve host: stick
curl: (6) Could not resolve host: to
curl: (3) [globbing] unmatched close brace/bracket in column 8

Thank you for the replies. It has been helpful. I am new to this so requesting guidance. Thanks again!

Use something like -d ‘{ ... JSON ...}’

So simple quotes.

(But installing Kibana and using developer console is even better)

Hey dadoonet,

I think I found the issue, it worked when I used -X POST. It finally created document for me.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.