Skip to content

Instantly share code, notes, and snippets.

@nanonanomachine
Created November 23, 2015 10:11
Show Gist options
  • Save nanonanomachine/0702734c647f3d7ca5d3 to your computer and use it in GitHub Desktop.
Save nanonanomachine/0702734c647f3d7ca5d3 to your computer and use it in GitHub Desktop.
最強に雑なmboxデータelasticsearch取り込み
require "bundler/setup"
require "kconv"
Bundler.require
client = Elasticsearch::Client.new log: true
bulk_requests = Array.new
# mbox
mboxes = Mbox.open("./gmail.mbox")
for i in 0..(mboxes.length-1)
begin
client.index index: 'gmail', type: 'gmail', id: i,
body:{
from: mboxes[i].headers[:from].toutf8,
to: mboxes[i].headers[:to].toutf8,
body: mboxes[i].content.first.to_s.toutf8.gsub(/(\r\n|\r|\n|\f)/,""),
date: DateTime.parse(mboxes[i].headers[:date])
}
rescue
next
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment