Contenu connexe Similaire à elasticsearchプラグイン入門 (20) elasticsearchプラグイン入門2. 名前: 菅谷信介
所属: N2SM, Inc.
オープンソース活動:
– Apache Portals、codehaus、Seasarプロジェクトなど
– Fessプロジェクト運営
などなど・・・
Twitter: @shinsuke_sugaya
ブログ: http://www.chazine.com/
自己紹介
2
6. Analysis: Analyzer関連の変換系
River: データを取り込む系
Transport: 他とやりとりする系
Site: 統計情報などサイト表示系(作り方はちょっと例外的)
Script: Pythonとか多言語実行系
その他: いろいろ…
プラグインの種類
6
8. ディレクトリ構成図例
8
├── pom.xml
└── src
└── main
├── assemblies
│ └── plugin.xml
├── java
│ └── <package name>
│ ├── plugin
│ │ ├── ...Module.java
│ │ └── ...Plugin.java
│ └── rest
│ └── ...RestAction.java
└── resources
└── es-plugin.properties ①
②
10. モジュールやサービスの登録や設定など行う
Pluginクラス
10
public class SolrPlugin extends AbstractPlugin {
@Override
public String name() {
return "SolrPlugin";
}
@Override
public String description() {
return "This plugin provides Solr interface on the elasticsearch.";
}
@Override
public void processModule(final Module module) {
if (module instanceof RestModule) {
((RestModule) module).addRestAction(SolrUpdateRestAction.class);
((RestModule) module).addRestAction(SolrSearchRestAction.class);
}
}
@Override
public Collection<Class<? extends Module>> indexModules() {
final Collection<Class<? extends Module>> modules = new ArrayList<Class<? extends Module>>();
modules.add(SolrIndexModule.class);
return modules;
}
}
AbstractPluginを継承するAbstractPluginを継承する
11. Pluginクラスの例
11
@Override
public void processModule(final Module module) {
if (module instanceof RestModule) {
((RestModule) module)
.addRestAction(SolrUpdateRestAction.class);
((RestModule) module)
.addRestAction(SolrSearchRestAction.class);
}
}
@Override
public Collection<Class<? extends Module>> indexModules() {
Collection<Class<? extends Module>> modules
= new ArrayList<Class<? extends Module>>();
modules.add(SolrIndexModule.class);
return modules;
}
HTTP等でリクエストを
処理したい場合
RestActionを登録
HTTP等でリクエストを
処理したい場合
RestActionを登録
サービス等のモジュールを作り
コンポーネントを登録する
サービス等のモジュールを作り
コンポーネントを登録する
15. maven-shade-pluginによりパッケージ名が変えら
れている
例: org.joda→org.elasticsearch.common.joda
RestRequestから複数の値を持つリクエストパラ
メータが取得できない
…/hoge?a=1&a=2&a=3 → a=[1,2,3]ではとれない
pom.xmlに記述した依存関係で成果物ができないの
で、zipにjarを入れ忘れたり…
非同期なので、デバッグを注意する
作る上でのポイント
15
18. elasticsearchのインストール
tar zxvf elasticsearch-0.90.3.tar.gz
プラグインのインストール
./bin/plugin -install elasticsearch-solr-api -url
http://maven.codelibs.org/org/codelibs/elasticsearch-
solr-api/1.2.1/elasticsearch-solr-api-1.2.1.zip
elasticsearchの実行
./bin/elasticsearch
以下のURLでSolrのようにアクセスできる:
http://hostname:9200/[index]/[type]/_solr
導入手順
18
19. 簡単に導入できるOSS全文検索システム
Apache Solrを検索エンジンとして利用
Apacheライセンスで提供
Webサイトやファイルシステムのクロール
データベースもクロール可能
ブラウザによる管理画面
MS Office、PDF、圧縮ファイルもサポート
ログイン状態で検索結果の出し分け可能
登録したカテゴリごとに検索可能
・・・などなど機能多数
Fessとは
19
21. curl -XPUT
'http://127.0.0.1:9200/solr/core1/_mapping' -d '…'
Fessで利用するmappingを作成
21
"properties" : {
"id" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"},
"parentId" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"},
"segment" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"},
"digest" : {"type" : "string", "store" : "yes"},
"boost" : {"type" : "float", "store" : "yes", "null_value" : 1.0},
"host" : {"type" : "string", "store" : "yes"},
"site" : {"type" : "string", "store" : "yes"},
"url" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"},
"content" : {"type" : "string", "store" : "yes"},
"title" : {"type" : "string", "store" : "yes"},
"cache" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"},
"tstamp" : {"type" : "solr_date", "store" : "yes"},
"anchor" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"},
"contentLength" : {"type" : "long", "store" : "yes"},
"lastModified" : {"type" : "solr_date", "store" : "yes"},
"lang" : {"type" : "string", "store" : "yes"},
"mimetype" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"},
"type" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"},
"label" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"},
"role" : {"type" : "string", "store" : "yes", "index" : "not_analyzed"}
}