Skip to content

Instantly share code, notes, and snippets.

@yteraoka
Created February 2, 2014 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yteraoka/8770630 to your computer and use it in GitHub Desktop.
Save yteraoka/8770630 to your computer and use it in GitHub Desktop.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment