ドキュメント処理を実行し、Elasticsearch インデックスにドキュメントを追加する Java コンソール アプリケーションを作成しています。Elasticsearch との通信を処理するために単純なラッパー クラスを使用しています。
このラッパー クラスからの関連する抜粋は、次のgetClientConnection()
メソッドです。
protected Client getClientConnection()
{
if (this.client == null)
{
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", this.clustername).build();
this.client = new TransportClient(settings)
.addTransportAddresses(new InetSocketTransportAddress(this.hostname, this.port));
}
return this.client;
}
そしてaddToIndex()
方法:
public void addToIndex(List<HashMap<String, Object>> documents, String index, String doctype)
{
Client client = this.getClientConnection();
BulkRequestBuilder bulkRequest = client.prepareBulk();
IndexRequestBuilder requestBuilder = client.prepareIndex(index, doctype);
for (HashMap<String, Object> curDocument : documents)
{
requestBuilder.setSource(curDocument);
bulkRequest.add(requestBuilder);
}
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
this.closeClientConnection();
}
コンソール アプリケーションからこのコードを呼び出すと、すべてが適切に機能し、ドキュメントがインデックスに追加されますが、実行すると警告メッセージが表示されます。
log4j:WARN No appenders could be found for logger (org.elasticsearch.plugins).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Elastic がログに log4j を使用していることは知っていますが、なぜ、何をログに記録しようとしているのかはわかりません。
これはスタンドアロン アプリケーションであるため、elasticsearch 構成ディレクトリをクラス パスに追加したくありません。アプリケーションは、Elastic を実行していないマシンで実行できる必要があります。私のアプリケーションでは、ログの目的で log4j2 を使用していることにも注意してください。
今私の質問:
TransportClient のロガーを無効にすることは可能ですか? 設定オブジェクトの引数を取る LogConfigurator.configure メソッドを見ましたが、その使用方法がわかりません。
自分のロガーを TransportClient に挿入することはできますか?