0

JESTを使用して、Elasticsearch HTTP アクセスをTitan ES クライアントに追加しようとしています。titan-es は、ES のローカルおよびトランスポート (TCP) モードのみをサポートします。しかし、ES の HTTP インターフェイスを介した通信をサポートしたいと考えています。これにより、クライアント ライブラリは、HTTP(S) インターフェイスのみを提供するインデックス作成バックエンドとしてAWS Elasticsearchを使用できるようになります。詳細については、この投稿を参照してください。titan-es

これまでに検討しているアプローチに関するフィードバックを探しています。

  1. ElasticsearchHttpClientインターフェイスを実装する新しいクラスを作成しorg.elasticache.client.Clientます。新しいクラスは、JestClient内部クライアントとして を使用します。このようにして、HTTP 経由で ES と通信します。AbstractClient新しいクラスは、実装する必要があるメソッドを減らすためにES を拡張する可能性があります: admin()settings()execute()threadPool()、およびclose().
  2. HTTP_CLIENT新しい列挙型を追加ElasticSearchSetup
  3. connect()メソッド onが、およびの適切な値を含むHTTP_CLIENTのインスタンスを返すことを確認します。メンバーは、新しいクラスのインスタンスになります。ConnectionnodeclientclientElasticsearchHttpClient
  4. が として構成されている場合、メソッドが(新しい を含む)ElasticSearchIndex.interfaceConfiguration()の正しいインスタンスを取得することを確認します。その時点から、残りのコードは新しいプロトコルで引き続き機能するはずです。ConnectionElasticsearchHttpClientINTERFACEHTTP_CLIENT

それはうまくいくように聞こえますか?最初のステップは私の最大の関心事です。JestClient を使用してすべてのクライアント メソッドを実装できるとは確信していません。

package com.thinkaurelius.titan.diskstorage.es;

import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.JestResult;
import io.searchbox.client.config.HttpClientConfig;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.*;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.support.AbstractClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;

import java.io.IOException;

public class ElasticsearchHttpClient extends AbstractClient {
    private final JestClient internalClient;
    private final ThreadPool pool;

    public ElasticsearchHttpClient(String hostname, int port) {
        JestClientFactory factory = new JestClientFactory();
        factory.setHttpClientConfig(new HttpClientConfig
                .Builder(String.format("http://%s:%d", hostname, port))
                .multiThreaded(true)
                .build());
        JestClient client = factory.getObject();

        this.pool = new ThreadPool("jest");
        this.internalClient = client;
    }

    @Override
    public AdminClient admin() {
        return null;
    }

    @Override
    public Settings settings() {
        return null;
    }

    @Override
    public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder, Client> action, Request request) {
        try {
            JestResult response = internalClient.execute(convertRequest(action, request));
            return convertResponse(response);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>> void execute(Action<Request, Response, RequestBuilder, Client> action, Request request, ActionListener<Response> listener) {
        execute(action, request);
    }

    private <Response extends ActionResponse> ActionFuture<Response> convertResponse(JestResult result) {
        // TODO How to convert a JestResult a Elasticsearch ActionResponse/ActionFuture?
        return null;
    }

    private <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>> io.searchbox.action.Action<JestResult> convertRequest(Action<Request, Response, RequestBuilder, Client> action, Request request) {
        // TODO How to convert an Elasticsearch Action<..> and Request to a Jest Action<JestResult>?
        return null;
    }

    @Override
    public ThreadPool threadPool() {
        return pool;
    }

    @Override
    public void close() throws ElasticsearchException {
        pool.shutdownNow();
    }
}

[ Titan メーリング リストElasticsearch フォーラムでも質問しました。]

4

1 に答える 1

2

Titan メーリング リストに回答を投稿しました。

Titan の観点から行う必要があるのは、IndexProvider インターフェイスを実装することです。私の推測では、Jest を完全な Elasticsearch クライアントのように見せることは現実的ではありません。

JestHttpClient を使用すると思います。Jest インターフェイスを実装する必要はありません。IndexProvider には、インデックスを作成/削除/変更/クエリするメソッドがあり、HTTP 経由で実行できるはずです。Elasticsearch HTTP ドキュメントをチェックして、JestHttpClient を使用して IndexProvider で必要なすべてのメソッドを実行できるかどうかを確認してください。

NODE と TRANSPORT を実行する IndexProvider の ElasticSearchIndex 実装が既にあります。HTTP または JEST オプションを追加しようとしています。そのため、変更を ElasticSearchIndex に押し込むことを検討するかもしれませんが、2 つの既存の impl は両方とも完全な Elasticsearch クライアントであるため、それがうまくいくかどうかはわかりません。おそらく、別の ElasticSearchHttpIndex を作成することを検討してください。よりクリーンな場合は、IndexProvider を実装します。

于 2016-01-15T19:54:35.057 に答える