Skip to content

Instantly share code, notes, and snippets.

@karmi
Created February 27, 2011 13:02
Show Gist options
  • Save karmi/846159 to your computer and use it in GitHub Desktop.
Save karmi/846159 to your computer and use it in GitHub Desktop.
Putting Github issues into ElasticSearch
require 'rubygems'
require 'uri'
require 'yajl'
require 'yajl/http_stream'
require 'rest_client'
require 'slingshot'
URLS = %w[
http://github.com/api/v2/json/issues/list/karmi/elasticsearch.github.com/open
http://github.com/api/v2/json/issues/list/karmi/elasticsearch.github.com/closed
]
issues = []
URLS.each do |url|
response = RestClient.get url
results = Yajl::Parser.parse(response)
issues += results['issues']
end
# p issues
# {
# "votes"=>0,
# "number"=>1,
# "position"=>1.0,
# "gravatar_id"=>"4e515deb518e9195f0dc45ec2af6a541",
# "created_at"=>"2011/02/26 09:08:20 -0800",
# "title"=>"Test issue (1)",
# "body"=>"This is the first testing issue for ES integration...",
# "comments"=>0,
# "updated_at"=>"2011/02/26 09:08:20 -0800",
# "labels"=>
# [
# ],
# "user"=>"karmi",
# "state"=>"open"
# }
index = Slingshot.index 'elastic-search-website'
issues.each do |issue|
issue['id'] = issue['number']
p index.store( 'issue', issue)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment