
By: Vinoth Chandar – CC BY 2.0
インストール
公式でインストール済みのElasticSearchに対応するバージョンを確認しておく.
elastic/elasticsearch-mapper-attachments
1 2 | cd /usr/share/elasticsearch sudo bin/plugin install elasticsearch/elasticsearch-mapper-attachments/2.5.0 |
チュートリアル
サンプル用のpdfをダウンロード
1 | wget http://www.intersil.com/data/fn/fn6742.pdf |
mappingでattachmentタイプを指定
1 2 3 4 5 6 7 8 9 10 11 12 | curl -X PUT "localhost:9200/test" curl -X PUT "localhost:9200/test/document/_mapping" -d ' { "document": { "properties": { "file": { "type": "attachment" } } } } ' |
Base64形式で保存
1 2 3 | coded=`cat fn6742.pdf | perl -MMIME::Base64 -ne 'print encode_base64($_)'` json="{\"file\":\"${coded}\"}" echo "$json" > json.file |
1 | curl -X POST "localhost:9200/test/attachment/" -d @json.file |
Rock’n’Roll
該当ファイルがヒットすればOK
1 | curl -X GET "http://192.168.11.222:9200/test/document/_search?q='amplifier'" |
情報
上記のチュートリアルでは検索結果のハイライトの方法もある
また、次のページでは日本語全文検索との組み合わせの情報がある.
Elasticsearch ウェブクローラー PDF編