문제

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.

도움이 되었습니까?

해결책 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.

다른 팁

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'})
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top