# Adding Documents via REST API in ElasticSearch

**URL:** <https://discuss.elastic.co/t/adding-documents-via-rest-api-in-elasticsearch/343102>\
**Category:** Elasticsearch\
**Created:** [September 15, 2023, 5:20am UTC](https://discuss.elastic.co/t/adding-documents-via-rest-api-in-elasticsearch/343102 "2023-09-15T05:20:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanyam](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sanyam](https://discuss.elastic.co/u/sanyam)\
**Post date:** [September 15, 2023, 5:20am UTC](https://discuss.elastic.co/t/adding-documents-via-rest-api-in-elasticsearch/343102/1 "2023-09-15T05:20:08Z")

</div>

I am getting this error while trying to run this code to add data/document In Elasticsearch version 6.4.1 in windows

curl -X POST "localhost:9200/clusters/\_doc" -H "Content-Type" : application/json -d "{ "field1":"value1", "field2": "value2", "field3" : "value3"}"

{"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 ('f' (code 102)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@f397fba; line: 1, column: 4]"}},"status":400}

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 15, 2023, 5:25am UTC](https://discuss.elastic.co/t/adding-documents-via-rest-api-in-elasticsearch/343102/2 "2023-09-15T05:25:56Z")

</div>

Version 6.4.1 is very, very old and has been EOL for years. I would recommend you upgrade to the latest version.

It looks like your request is malformed. Try this instead: `curl -X POST "localhost:9200/clusters/_doc" -H "Content-Type: application/json" -d '{ "field1":"value1", "field2": "value2", "field3" : "value3"}'`

---

<div class="post-metadata">

**Author:** ![sanyam](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sanyam](https://discuss.elastic.co/u/sanyam)\
**Post date:** [September 15, 2023, 5:55am UTC](https://discuss.elastic.co/t/adding-documents-via-rest-api-in-elasticsearch/343102/3 "2023-09-15T05:55:27Z")

</div>

I tried starting the v8.9.1 but started giving me errors, so that's why I chose this version.

I tried running your code and it again gave me this:  
curl -X POST "localhost:9200/clusters/\_doc" -H "Content-Type: application/json" -d '{"field1":"value1", "field2": "value2", "field3" : "value3"}'

{"error":{"root\_cause":[{"type":"mapper\_parsing\_exception","reason":"failed to parse"}],"type":"mapper\_parsing\_exception","reason":"failed to parse","caused\_by":{"type":"not\_x\_content\_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}},"status":400}  
curl: (6) Could not resolve host: field2  
curl: (6) Could not resolve host: value2,  
curl: (6) Could not resolve host: field3  
curl: (3) URL using bad/illegal format or missing URL  
curl: (3) unmatched close brace/bracket in URL position 7:  
value3}'

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 15, 2023, 6:24am UTC](https://discuss.elastic.co/t/adding-documents-via-rest-api-in-elasticsearch/343102/4 "2023-09-15T06:24:56Z")

</div>

I just noticed that you are using Windows. Curl on Windows is not the same as standard curl, so it may be a Windows specific issue. I would recommend trying to create the document in the Kibana dev tools console. You may also try some other tool, e.g. Postman, to send the request.

---

<div class="post-metadata">

**Author:** ![sanyam](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sanyam](https://discuss.elastic.co/u/sanyam)\
**Post date:** [September 15, 2023, 6:45am UTC](https://discuss.elastic.co/t/adding-documents-via-rest-api-in-elasticsearch/343102/5 "2023-09-15T06:45:18Z")

</div>

I see, thank you @Christian_Dahlqvist

---

<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:** [October 13, 2023, 6:46am UTC](https://discuss.elastic.co/t/adding-documents-via-rest-api-in-elasticsearch/343102/6 "2023-10-13T06:46:01Z")

</div>

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