#!/home/ytera/ruby-2.1.0/bin/ruby
require 'csv'
require 'json'
require 'net/http'
require 'uri'
indexname = 'ldgourmet'
documentname = 'restaurant'
http = Net::HTTP.new("localhost", 9200)
reader = CSV.open("datasets/restaurants.csv", "r")
header = reader.take(1)[0]
reader.each do |row|
hash = Hash[*[header, row].transpose.flatten]
id = hash.delete("id")
put_data = JSON::dump(hash)
res = http.request_put("/#{indexname}/#{documentname}/#{id}", put_data)
puts res.body
end
Created
February 2, 2014 16:12
-
-
Save yteraoka/8770630 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment