# How to insert JSON data directly to elastic search using curl command?

**URL:** <https://discuss.elastic.co/t/how-to-insert-json-data-directly-to-elastic-search-using-curl-command/160046>\
**Category:** Elasticsearch\
**Created:** [December 9, 2018, 1:08pm UTC](https://discuss.elastic.co/t/how-to-insert-json-data-directly-to-elastic-search-using-curl-command/160046 "2018-12-09T13:08:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bugnet17](https://avatars.discourse-cdn.com/v4/letter/b/cdc98d/32.png) [@bugnet17](https://discuss.elastic.co/u/bugnet17)\
**Post date:** [December 9, 2018, 1:08pm UTC](https://discuss.elastic.co/t/how-to-insert-json-data-directly-to-elastic-search-using-curl-command/160046/1 "2018-12-09T13:08:57Z")

</div>

I'm trying to insert data directly to elastic search into a specific index called "cars" via the curl command but it is constantly encountering errors.

```auto
curl -XPOST http://elk.local:9200/cars/doc -H "Content-Type: application/json" -d @test.json

```

JSON Example:

```auto
{
"name":"John",
"age":30,
"cars":["Ford", "BMW", "Fiat"]
}

```

Error:  
{"error":{"root\_cause":[{"type":"illegal\_argument\_exception","reason":"Rejecting mapping update to [cars] as the final mapping would have more than 1 type: [log, doc]"}],"type":"illegal\_argument\_exception","reason":"Rejecting mapping update to [cars] as the final mapping would have more than 1 type: [log, doc]"},"status":400}

---

<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:** [December 9, 2018, 2:11pm UTC](https://discuss.elastic.co/t/how-to-insert-json-data-directly-to-elastic-search-using-curl-command/160046/2 "2018-12-09T14:11:43Z")

</div>

You already created a document in your index with another type name.  
Drop the index first if you don't care about the existing data.

---

<div class="post-metadata">

**Author:** ![bugnet17](https://avatars.discourse-cdn.com/v4/letter/b/cdc98d/32.png) [@bugnet17](https://discuss.elastic.co/u/bugnet17)\
**Post date:** [December 9, 2018, 2:22pm UTC](https://discuss.elastic.co/t/how-to-insert-json-data-directly-to-elastic-search-using-curl-command/160046/3 "2018-12-09T14:22:00Z")

</div>

It does not matter, I always get the same error.

and if I'm not specify document:

```auto
curl -XPOST http://elk.local:9200/cars/ -H "Content-Type: application/json" -d @test.json

```

I got next error:  
{"error":"Incorrect HTTP method for uri [/cars/] and method [POST], allowed: [PUT, HEAD, GET, DELETE]","status":405}

---

<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:** [December 9, 2018, 2:50pm UTC](https://discuss.elastic.co/t/how-to-insert-json-data-directly-to-elastic-search-using-curl-command/160046/4 "2018-12-09T14:50:06Z")

</div>

Run:

```
curl -XDELETE http://elk.local:9200/cars
curl -XPOST http://elk.local:9200/cars/doc -H "Content-Type: application/json" -d @test.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:** [January 6, 2019, 2:50pm UTC](https://discuss.elastic.co/t/how-to-insert-json-data-directly-to-elastic-search-using-curl-command/160046/5 "2019-01-06T14:50:08Z")

</div>

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