Search code examples
ruby-on-railsrubyruby-on-rails-3curlrest-client

Ruby equivalent of this curl command


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.


Solution

  • 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.