###課題
・mysqlの親子関係テーブルのデータをelasticsaerchに流し込めない。
親テーブルのデータは入るが、それに紐づく子テーブルのデータを登録できない。
jdbc importerプラグインを使用してデータ連携をしたことがある方、embulkなど他のツールで経験ある方ご教授いただけたら幸いです。
###やりたいこと
・mysqlにて親子関係になっているテーブルデータをElasticsearchから検索したい。
・mysqlとelasticsearchで同期を取りたい。
###実施内容
mysqlからelasticsearchへのデータ連携は下記プラグインを使用。
jdbc importer
同期をとるため、jdbc importerプラグインをスケジューリング(X分間おきにバッチ連携)している。
・Elasticsearchのmappingは下記の通り設定
elasticsearch
1{ 2 "mappings":{ 3 "books":{ 4 "_id":{ 5 "index":"not_analyzed", 6 "path":"book_id" 7 }, 8 "properties":{ 9 "book_id":{"type":"integer","index":"not_analyzed}, 10 "title":{"type":"string"} 11 } 12 }, 13 "tags":{ 14 "_id":{ 15 "index":"not_analyzed", 16 "path":"tag_id" 17 }, 18 "_parent":{ "type":"books"}, 19 "properties":{ 20 "tag_id":{"type":"integer","index":"not_analyzed}, 21 "name":{"type":"string"} 22 } 23 } 24}
book,tagテーブル毎に下記の通りシェルファイルを作成。
echo'{ "type":"jdbc", "jdbc":{ "url":"jdbc:mysql://localhost:3306/mydb", "user":"root", "password":"password", "index":"elastic", "type":"books", "sql":"select book_id as _id, title from book" } }
echo'{ "type":"jdbc", "jdbc":{ "url":"jdbc:mysql://localhost:3306/mydb", "user":"root", "password":"password", "index":"elastic", "type":"tags", "sql":"select tag_id as _id, book_id as _parent, name from tag" } }
上記を実行すると、bookテーブルのデータはElasticsearch上に連携できるが、tagテーブルの値が入らない。
typeは両方作成される。
mysqlのテーブル構成
bookテーブルとtagテーブルはn:mの関係で、間にbook_idとtag_idを保持しているリンクテーブルがあります。
###バージョン情報
mysql:5.6.21
Elasticsearch:1.7.2
jdbc importer:1.7.2.1
あなたの回答
tips
プレビュー