Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content-type header not supported

I am following this link for elasticsearch.

https://www.elastic.co/blog/a-practical-introduction-to-elasticsearch

I am trying following curl to post the json data.

curl -XPOST "http://localhost:9200/shakespeare/_bulk?pretty" --data-binary @D:\data\shakespeare.json

But I am getting error like below:

{
  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
  "status" : 406
}
like image 889
nas Avatar asked Jul 17 '18 09:07

nas


People also ask

What is Content-Type in header?

The Content-Type header is used to indicate the media type of the resource. The media type is a string sent along with the file indicating the format of the file. For example, for image file its media type will be like image/png or image/jpg, etc. In response, it tells about the type of returned content, to the client.

Is Content-Type header mandatory?

Nope, Content-Type is not a required field. It's not mandatory per the HTTP 1.1 specification. Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body.

What is header (' Content-Type application json ')?

The function header("Content-type:application/json") sends the http json header to the browser to inform it what kind of data it expects.


2 Answers

You need to set the content type in the header to application/json:

curl -XPOST -H "Content-Type: application/json" "http://localhost:9200/shakespeare/_bulk?pretty" --data-binary @D:\data\shakespeare.json
like image 123
Philip Bergström Avatar answered Sep 24 '22 12:09

Philip Bergström


I received the same error after updating from an older version to 6.x.x. I'm not using curl statements directly, I'm using python's elasticsearch plugin.

In my case, I needed to install the newer version of the plugin that corresponded to the updated elasticsearch server.

pip install elasticsearch==6.3.1

Make sure you run it in the same Python Environment that your code is executing in.

Hope this saves someone some headache.

like image 24
Caleb Postlethwait Avatar answered Sep 20 '22 12:09

Caleb Postlethwait