Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send JSON/XML/TXT/CSV files to ElasticSearch

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?

like image 752
Zain Mobhani Avatar asked Dec 19 '22 06:12

Zain Mobhani


2 Answers

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.

like image 160
Sam Upra Avatar answered Dec 20 '22 21:12

Sam Upra


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/
like image 26
Bala Krishna Avatar answered Dec 20 '22 21:12

Bala Krishna