Question

curl -s -XPOST localhost:9200/_bulk --data-binary @filename.json

I am looking at RestClient gem and cant figure out how to do this. I need this for making a bulk request to elasticsearch.

Was it helpful?

Solution 2

Using rest-client

RestClient.post 'localhost:9200/_bulk', File.new("filename.json", 'rb'), 'Content-type' => 'application/x-www-form-urlencoded'

not sure if rest-client automatically set content-type, just check without it.

OTHER TIPS

You can do this with the standard library (without any additional gems):

require 'uri'
require 'net/http'

uri = URI.parse('http://localhost:9200/_bulk')
data = File.read('filename.json')
http = Net::HTTP.new(uri.host, uri.port)

response, body = http.post(url.path, data, {'Content-type'=>'text/xml; charset=utf-8'})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top