# Unable to create document within an index

**URL:** <https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314>\
**Category:** Elasticsearch\
**Created:** [October 26, 2017, 12:06am UTC](https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314 "2017-10-26T00:06:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aisha1990](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Aisha1990](https://discuss.elastic.co/u/Aisha1990)\
**Post date:** [October 26, 2017, 12:06am UTC](https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314/1 "2017-10-26T00:06:43Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Canappeco](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@Canappeco](https://discuss.elastic.co/u/Canappeco)\
**Post date:** [October 26, 2017, 3:07am UTC](https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314/2 "2017-10-26T03:07:45Z")

</div>

Why you use `""name""`?

You should try this:

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

```

Hope it helps.

---

<div class="post-metadata">

**Author:** ![Aisha1990](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Aisha1990](https://discuss.elastic.co/u/Aisha1990)\
**Post date:** [October 26, 2017, 8:46pm UTC](https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314/3 "2017-10-26T20:46:36Z")

</div>

I tried that too. However, I get the below error -  
curl -XPUT "[http://localhost:9200/products/mobiles/1](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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 26, 2017, 9:09pm UTC](https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314/4 "2017-10-26T21:09:50Z")

</div>

You need to specify the content type.

See basic examples at

> <https://github.com/elastic/elasticsearch/blob/master/README.textile>

---

<div class="post-metadata">

**Author:** ![Aisha1990](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Aisha1990](https://discuss.elastic.co/u/Aisha1990)\
**Post date:** [October 27, 2017, 5:31am UTC](https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314/5 "2017-10-27T05:31:46Z")

</div>

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](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](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](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!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 27, 2017, 6:14am UTC](https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314/6 "2017-10-27T06:14:47Z")

</div>

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

So simple quotes.

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

---

<div class="post-metadata">

**Author:** ![Aisha1990](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Aisha1990](https://discuss.elastic.co/u/Aisha1990)\
**Post date:** [October 28, 2017, 11:19pm UTC](https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314/7 "2017-10-28T23:19:34Z")

</div>

Hey dadoonet,

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 25, 2017, 11:19pm UTC](https://discuss.elastic.co/t/unable-to-create-document-within-an-index/105314/8 "2017-11-25T23:19:44Z")

</div>

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