LoginSignup
10
10

More than 5 years have passed since last update.

【ES2.1.1】mysqlのデータをElasticsearchに突っ込む

Posted at

【ver2.1.1】CentOSにElasticSearchを入れて起動するまでの続きです!

環境(2016-1-12)

  • CentOS6.5
  • ElasticSearch2.1.1

概要

データのインポートにはEmbulkを使用します!!
EmbulkにはBigQueryやRedshiftそして今回のElasticSearchとめっちゃ助かってます

流れ

Embulkインストール

Embulk本体はhttps://github.com/embulk/embulk#linux--mac--bsdからどうぞ

使用するプラグインをインストール

今回は
inputにembulk-input-mysql
outputにembulk-output-elasticsearch
を使用する。
embulk-input-mysqlに関してはembulk gem install embulk-input-mysqlでいけるんだが
embulk-output-elasticsearchに関しては2016/1/12時点ではそのままインストールしてしまうと
runさせた時にFailed to deserialize exception response from streamで怒られるのでgitcloneしてbuildしないといけない。

cd [任意のディレクトリ ※今回は/tmpを例にする]
git clone https://github.com/muga/embulk-output-elasticsearch.git
cd embulk-output-elasticsearch
./gradlew gem

Elasticsearchの設定ファイルを編集

/etc/elasticsearch/elasticsearch.yml
# 下記を追加する。
# 今回はクラスタとかを組むわけではないので、このノードをマスターにする
# これを設定しないnodeないよ〜ってエラーになる。
node.master: true

設定ファイルを作成

config.yml
in:
  type: mysql
  user: [user名]
  password: [password]
  database: [データベース名]
  table: [テーブル名]
  host: [host]
  select: "*"
out:
  type: elasticsearch
  index: [index名]
  index_type: [indexのタイプ]
  nodes:
  - {host: localhost, port: 9300}

preview

shell
embulk preview -I /tmp/embulk-output-elasticsearch/lib config.yml

ポイントは-I /tmp/embulk-output-elasticsearch/libさきほど入れたembulk-output-elasticsearchを指定すること。
これを指定しないとエラーになる

run

shell
embulk run -I /tmp/embulk-output-elasticsearch/lib config.yml

実装確認

マッピングされているかの確認

curl -XGET 'http://localhost:9200/[index名]?pretty' 

データの保持されている数を調べる

curl -XGET 'http://localhost:9200/[index名]/[indexタイプ]/_count?pretty'

最後に

Embulkには本当に感謝です。

10
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10