Elasticsearch upgrade path from client client to high-level REST client

What is the upgrade path for an application that uses the native Java client Elasticsearch ( TransportClient

) API to move to using the high-level REST client for Java?

The documentation (preliminary?) Seems to indicate:

The high-level Java REST client depends on the core Elasticsearch project. It takes the same request arguments as TransportClient and returns the same response objects.

(Source: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.x/java-rest-high.html )

But I don't quite understand what that means. Will I be able to switch my entire codebase to a high-level REST client without rewriting my requests or other client-type operations? The REST client is not like an interface Client

. It might make sense from a denouement point of view. '

I need to know if I should build my own abstraction around client operations, or if I HighLevelRestClient

will basically implement the interface Client

.

Should I continue to write code regarding the TransportClient API, or will this code be overwritten if the TransportClient is deprecated?

Note that I am looking at a high-level REST client, not a low-level REST client.

+3


source to share


1 answer


The high-level REST client does not implement the interface Client

. The plan is described in this blogpost that I wrote a while ago.

We are also in the process of writing documentation that will include a page with instructions for migrating from a transport client.

The new client reuses requests and responses from the existing transport client, but the client object is incompatible, which means, for example, the following:

IndexRequest indexRequest = new IndexRequest("index", "type", "id");
indexRequest.source("field", "value");
IndexResponse indexResponse = transportClient.index(indexRequest).get();

      

will become something like:

IndexRequest indexRequest = new IndexRequest("index", "type", "id");
indexRequest.source("field", "value");
IndexResponse indexResponse = restHighLevelClient.index(indexRequest);

      

As for asynchronous requests, the call is slightly different (see method name), in the new client we went to a different method with a name that ends with the "Async" suffix, you should move from the following:

transportClient.index(indexRequest, new ActionListener<IndexResponse>() {
                    @Override
                    public void onResponse(IndexResponse indexResponse) {
                        // called when the operation is successfully completed
                    }

                    @Override
                    public void onFailure(Exception e) {
                        // called on failure
                    }
                });

      



to the next:

restHighLevelClient.indexAsync(indexRequest, new ActionListener<IndexResponse>() {
                @Override
                public void onResponse(IndexResponse indexResponse) {
                    // called when the operation is successfully completed
                }

                @Override
                public void onFailure(Exception e) {
                    // called on failure
                }
            });

      

Unfortunately, the methods are Client#prepare*

not available to the high level client, so something like:

IndexResponse indexResponse = transportClient.prepareIndex("index", "type", "id").setSource("field", "value").get();

      

needs to be rolled over to the previous value using ActionRequest

, not ActionRequestBuilder

s. We are making this change as there is always confusion between queries and builders in the transport client, there are two ways to do the same. The new customer will have one way of submitting requests.

If you want to take a look at the current documentation, it is already active, although work in progress: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high.html .

The high-level REST client will replace the Transport client, although its first version will only support indexes, scope, get, delete, update, search, search, and scrolling of the scroll APIs. Support for the missing APIs will follow, we are also open to user contributions as usual.

The transport client will soon be deprecated, so I would suggest moving with a high level REST client as soon as possible, this shouldn't be a huge change and it will pay off as we will be improving its overtime already running through REST - that's a big improvement.

+3


source







All Articles