# Index a new document

**URL:** <https://discuss.elastic.co/t/index-a-new-document/35281>\
**Category:** Elasticsearch\
**Created:** [November 23, 2015, 8:56am UTC](https://discuss.elastic.co/t/index-a-new-document/35281 "2015-11-23T08:56:38Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![gn00342691](https://avatars.discourse-cdn.com/v4/letter/g/f4b2a3/32.png) [@gn00342691](https://discuss.elastic.co/u/gn00342691)\
**Post date:** [November 23, 2015, 8:56am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/1 "2015-11-23T08:56:38Z")

</div>

Hi All,

I am trying to index a document into the customer index using the below command as suggested in the elasticsearch guide:  
**curl -XPUT localhost:9200/customer/external/1?Gibbon -d '{ "name": "John Doe"}'**

But wen I execute this command, I am getting the below error:

**{"error":{"root\_cause":[{"type":"mapper\_parsing\_exception","reason":"failed to p**  
**arse"}],"type":"mapper\_parsing\_exception","reason":"failed to parse","caused\_by"**  
**:{"type":"not\_x\_content\_exception","reason":"Compressor detection can only be ca**  
**lled on some xcontent bytes or compressed xcontent bytes"}},"status":400}curl: (**  
**6) Could not resolve host: name**  
**curl: (3) [globbing] unmatched close brace/bracket in column 9**

Can anyone help me to solve this.

The index is getting created properly.

---

<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:** [November 23, 2015, 9:20am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/2 "2015-11-23T09:20:53Z")

</div>

Where did you see this exact command? Can not find it in the guide.

---

<div class="post-metadata">

**Author:** ![gn00342691](https://avatars.discourse-cdn.com/v4/letter/g/f4b2a3/32.png) [@gn00342691](https://discuss.elastic.co/u/gn00342691)\
**Post date:** [November 23, 2015, 9:35am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/3 "2015-11-23T09:35:50Z")

</div>

Hi David,

I am refering the online documentation for elasticsearch. Please refer the below url which mentions this command:  
**[https://www.elastic.co/guide/en/elasticsearch/reference/current/\_index\_and\_query\_a\_document.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/_index_and_query_a_document.html)**

Can you please share the documents for the same if you have any, as i am a beginner in this tool?

Thanks.

---

<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:** [November 23, 2015, 9:50am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/4 "2015-11-23T09:50:35Z")

</div>

So this line does not come from the documentation:

```
curl -XPUT localhost:9200/customer/external/1?Gibbon -d '{ "name": "John Doe"}'

```

Try this:

```
curl -XPUT localhost:9200/customer/external/1 -d '{ "name": "John Doe"}'
```

---

<div class="post-metadata">

**Author:** ![gn00342691](https://avatars.discourse-cdn.com/v4/letter/g/f4b2a3/32.png) [@gn00342691](https://discuss.elastic.co/u/gn00342691)\
**Post date:** [November 23, 2015, 9:54am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/5 "2015-11-23T09:54:04Z")

</div>

Thanks David but the suggested command did not work. Showing below error:

**{"error":{"root\_cause":[{"type":"mapper\_parsing\_exception","reason":"failed to p**  
**arse"}],"type":"mapper\_parsing\_exception","reason":"failed to parse","caused\_by"**  
**:{"type":"not\_x\_content\_exception","reason":"Compressor detection can only be ca**  
**lled on some xcontent bytes or compressed xcontent bytes"}},"status":400}curl: (**  
**6) Could not resolve host: name**  
**curl: (3) [globbing] unmatched close brace/bracket in column 9**

---

<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:** [November 23, 2015, 10:07am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/6 "2015-11-23T10:07:29Z")

</div>

Can you do a print screen of what you are doing. I have hard time understanding.

---

<div class="post-metadata">

**Author:** ![gn00342691](https://avatars.discourse-cdn.com/v4/letter/g/f4b2a3/32.png) [@gn00342691](https://discuss.elastic.co/u/gn00342691)\
**Post date:** [November 23, 2015, 10:09am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/7 "2015-11-23T10:09:52Z")

</div>

![](https://us1.discourse-cdn.com/elastic/original/2X/f/fe306fb7a26c2c8275b25e4dba04dad8df9f28fa.png)

---

<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:** [November 23, 2015, 10:29am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/8 "2015-11-23T10:29:23Z")

</div>

Ok. So curl on windows really sucks. You should use a REST plugin for your browser to run REST calls.  
I personally use [SENSE](https://www.elastic.co/guide/en/sense/current/index.html) as it allows to copy CURL commands directly.

---

<div class="post-metadata">

**Author:** ![Willi](https://avatars.discourse-cdn.com/v4/letter/w/fbc32d/32.png) [@Willi](https://discuss.elastic.co/u/Willi)\
**Post date:** [January 3, 2016, 6:07pm UTC](https://discuss.elastic.co/t/index-a-new-document/35281/9 "2016-01-03T18:07:38Z")

</div>

I had the same poblem on Windows 8.1 and could solve it the following way:

1. Use " instead of ' to wrap the JSON document to be inserted
2. Mask the " within the document with "

So, your example should then look like this:  
curl -XPUT localhost:9200/customer/external/1 -d "{ "name": "John Doe"}"

Good luck!

---

<div class="post-metadata">

**Author:** ![Andrew\_D](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@Andrew\_D](https://discuss.elastic.co/u/Andrew_D)\
**Post date:** [July 1, 2016, 6:25pm UTC](https://discuss.elastic.co/t/index-a-new-document/35281/10 "2016-07-01T18:25:55Z")

</div>

For **Python** users with **requests** library:

python **requests.put()** (and **post()**) can give you the same error. This thread made me realize that the **data=document** parameter to **requests** must be a JSON string and not a **dict** object.

The **dict** object gets packed by \*_requests_. Maybe it's always form-encoded. Anyway, **Elasticsearch** doesn't like it.

Dump the _dict_\* as JSON first!

url = "[http://localhost:9200/the\_index/invoices/9780349139036](http://localhost:9200/the_index/invoices/9780349139036)"  
r = requests.put(url, data=json.dumps(doc\_dict), headers=JSON\_HEADERS)

---

<div class="post-metadata">

**Author:** ![Yuriy\_Chih](https://avatars.discourse-cdn.com/v4/letter/y/0ea827/32.png) [@Yuriy\_Chih](https://discuss.elastic.co/u/Yuriy_Chih)\
**Post date:** [July 19, 2016, 11:12am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/11 "2016-07-19T11:12:08Z")

</div>

Thanks, that works for me

---

<div class="post-metadata">

**Author:** ![Himanshu\_Kapoor](https://avatars.discourse-cdn.com/v4/letter/h/57b2e6/32.png) [@Himanshu\_Kapoor](https://discuss.elastic.co/u/Himanshu_Kapoor)\
**Post date:** [September 4, 2016, 10:33am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/12 "2016-09-04T10:33:09Z")

</div>

Yes looks like some issue with curl on windows. Sense worked. Thanks

---

<div class="post-metadata">

**Author:** ![nsarchar](https://avatars.discourse-cdn.com/v4/letter/n/c0e974/32.png) [@nsarchar](https://discuss.elastic.co/u/nsarchar)\
**Post date:** [March 6, 2017, 8:50pm UTC](https://discuss.elastic.co/t/index-a-new-document/35281/13 "2017-03-06T20:50:30Z")

</div>

That was the solution. You're awesome. Thanks.

---

<div class="post-metadata">

**Author:** ![Leon\_Nell](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Leon\_Nell](https://discuss.elastic.co/u/Leon_Nell)\
**Post date:** [April 4, 2017, 10:30am UTC](https://discuss.elastic.co/t/index-a-new-document/35281/14 "2017-04-04T10:30:31Z")

</div>

I know this is an old post. Just for completeness, windows does not support CURL commands natively. If you wish to use curl commands, I would recommend installing the 3rd party cURL using the following steps:

1. Download the appropriate CAB file for your system architecture from the following link: [https://curl.haxx.se/download.html](https://curl.haxx.se/download.html).
2. Extract the file into the c:\windows\system32 folder.
3. Open a Command prompt, and navigate to c:\windows\system32, and issue the appropriate cURL commands.

However, when in a Powershell console, or ISE, the Invoke-WebRequest cmdlet has an alias called 'curl', so should not be confused with the \*nix equivalent. To create an index using Powershell's Invoke-Webrequest, use the following:

Invoke-WebRequest -Method PUT -Uri [http://localhost:9200/](http://localhost:9200/)`<index`\>

List your indices as follows:

Invoke-WebRequest –Method GET –Uri [http://localhost:9200/\_cat/indices?v](http://localhost:9200/_cat/indices?v) | Select Content | Format-List

Index a document:

$name = @{"name" = "John Doe"}  
$json = $name | ConvertTo-Json

Invoke-WebRequest -Method PUT -Uri "[http://localhost:9200/customer/external/1](http://localhost:9200/customer/external/1)" -Body $json -ContentType 'application/json'

---

<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:** [July 5, 2017, 10:01pm UTC](https://discuss.elastic.co/t/index-a-new-document/35281/15 "2017-07-05T22:01:31Z")

</div>


