4

I have been trying to send some data in various formats to ElasticSearch running on my computer.

I am running Ubuntu 17 (the latest release) and am unable to do so.

Here are the commands I'm using on Terminal:

curl -X POST 'http://localhost:9200/json/test/2' -d @json.json     

I am in the correct directory where the files are. Here is the error I'm getting:

{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

I've searched online to no avail.

What am I doing wrong?

2 Answers 2

9

You can do something like this :

curl -XPUT 'localhost:9200/twitter/tweet/1?pretty' -H 'Content-Type: application/json' -d'
{
    "user" : "kimchy",
    "post_date" : "2009-11-15T14:12:12",
    "message" : "trying out Elasticsearch"
}
'

The reason your request wasn't passing because you didnt specify the Content-Type as JSON. Plus, you should use PUT and not POST :) I copied this request from this documentation : https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html. Cheers.

Sign up to request clarification or add additional context in comments.

3 Comments

Now I'm getting this from Terminal. { "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: application curl: (6) Could not resolve host: json_products.json
I'm not sure I follow.
Thanks. So i learned from elastic.co/blog/… this new addition enforcing http.content_type.required to be true starting from version 6.0.0
2

The error you're seeing is due to the version of the Elastic Search being different. Before -XPUT, add -H 'Content-Type: application/json'

Here is an example:

curl -H 'Content-Type: application/json' -XPUT 127.0.0.1:9200/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.