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?
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With