Skip to content

Instantly share code, notes, and snippets.

@uiur
Last active August 29, 2015 14:19
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 uiur/a03e553c20de1ef1da28 to your computer and use it in GitHub Desktop.
Save uiur/a03e553c20de1ef1da28 to your computer and use it in GitHub Desktop.
euc-jp -> utf-8
require 'json'
list = Dir.glob('wiki/*.txt').map do |path|
title = `echo #{path} | xxd -r -p | nkf -E -w`
body = `cat #{path} | nkf -E -w`
{
title: title,
body: body
}
end
puts JSON.pretty_generate(list)
@uiur
Copy link
Author

uiur commented Apr 20, 2015

require 'elasticsearch'
require 'json'

client = Elasticsearch::Client.new(url: 'http://sharp:9200')

body = JSON.parse(File.open('pages.json').read).flat_map do |data|
  [
    { index: {} },
    data
  ]
end

client.bulk(index: 'wiki', type: 'page', body: body)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment