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

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.

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

JSON Example:

{
"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}

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.

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

and if I'm not specify document:

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}

Run:

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

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