Elasticsearch upgrade path from transport client to advanced REST client


microphone

What is the upgrade path for an application that uses the Elasticsearch native Java client API ( TransportClient) to migrate to an advanced REST client that uses Java ?

Documentation (preliminary?) seems to indicate:

The Java advanced REST client depends on the Elasticsearch core project. It accepts the same request parameters as TransportClient and returns the same response object.

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

But I don't know what that means. Can I switch my entire codebase to an advanced REST client without rewriting queries or other client type operations? The REST client doesn't seem to implement that interface. This might make sense from a decoupling perspective. "Client

What I need to know is whether I should build my own abstraction around the client operations or should I already basically implement the interface.HighLevelRestClientClient

Should I continue writing code against the TransportClient API for now, or do I need to rewrite all this code when TransportClient is deprecated?

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

Java

Advanced REST clients do not implement this Clientinterface. I described the plan in this blog post I wrote a while back .

We are also in the process of writing the documentation, which will include a page with instructions on how to migrate from the transport client.

The new client reuses the requests and responses of the existing transport client, but the client objects are not compatible, 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 this:

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

For asynchronous requests, the calls are slightly different (see method names), in the new client we use other methods with names ending with "Async" suffix, you can do it from:

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 following:

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, these Client#prepare*methods won't work in the advanced client, so look like this:

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

Need to use ActionRequestinstead of ActionRequestBuilders to migrate to the above version . We're making this change because there's always been a confusion between requests and builders in the transport client, which are two ways of doing the exact same thing. New clients will have only one way to provide requests.

If you want to see the current documentation, it's already there, although it's 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 upcoming release only supports the index, bulk, get, delete, update, search, search scroll and clear scroll APIs. The missing API will be supported next, and we will also open it up to users as usual.

The shipping client will be deprecated soon so I recommend moving the advanced REST client asap, this shouldn't be a huge change, it will pay off as we'll be addressing it by incrementally improving it REST is a big one progress.

Related


elasticsearch transport client with url path

Shakul Hameed My elasticsearch wrapped in tomcat using transport software is up and running in a cluster of 20 computers on a specific path /essearch. I have load balancer before clustering with dns, so I use www.dns.com/essearch/ to access elastic search Now

elasticsearch transport client with url path

Shakul Hameed My elasticsearch wrapped in tomcat using transport software is up and running in a cluster of 20 computers on a specific path /essearch. I have load balancer before clustering with dns, so I use www.dns.com/essearch/ to access elastic search Now

Elasticsearch Transport client connection

Akshay Bijawe I am building a Search Web Application with a servlet connected to Elasticsearch. I have a question about Elasticsearch 's shipping module . I am using TransportClient in a class implementing ServletContextListener to open a connection to Elastic

Elasticsearch REST advanced client combined with query builder

Bogotou I need to create something like advanced search using ES REST Advanced Client (Java). First, I have a search keyword that searches all fields. I use QueryStringQueryBuilderthis. SearchSourceBuilder ticketInfoSourceBuilder = new SearchSourceBuilder(); t

Elasticsearch Advanced Rest Client Java sorting not working

Bogi Manotoi I am very new to Elasticsearch High Level Rest Client (Java). I have a very simple query that lists all records, but the sorting doesn't seem to be working properly. Some fields are text type so I need to set fielddata to true. renew: Thanks Andre

Elasticsearch REST advanced client combined with query builder

Bogotou I need to create something like advanced search using ES REST Advanced Client (Java). First, I have a search keyword that searches all fields. I use QueryStringQueryBuilderthis. SearchSourceBuilder ticketInfoSourceBuilder = new SearchSourceBuilder(); t

Elasticsearch REST advanced client combined with query builder

Bogotou I need to create something like advanced search using ES REST Advanced Client (Java). First, I have a search keyword that searches all fields. I use QueryStringQueryBuilderthis. SearchSourceBuilder ticketInfoSourceBuilder = new SearchSourceBuilder(); t

Elasticsearch REST advanced client combined with query builder

Bogotou I need to create something like advanced search using ES REST Advanced Client (Java). First, I have a search keyword that searches all fields. I use QueryStringQueryBuilderthis. SearchSourceBuilder ticketInfoSourceBuilder = new SearchSourceBuilder(); t

ElasticSearch Long Term Query Using Java Advanced REST Client

if there is a mahdi The java high level rest client provides a way to search using a term on elasticsearch whose code is shown below SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); sourceBuilder.query(QueryBuilders.termQuery("user", "kimchy"));

ElasticSearch Long Term Query Using Java Advanced REST Client

if there is a mahdi The java high level rest client provides a way to search using a term on elasticsearch whose code is shown below SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); sourceBuilder.query(QueryBuilders.termQuery("user", "kimchy"));

ElasticSearch Long Term Query Using Java Advanced REST Client

if there is a mahdi The java high level rest client provides a way to search using a term on elasticsearch whose code is shown below SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); sourceBuilder.query(QueryBuilders.termQuery("user", "kimchy"));

ElasticSearch Long Term Query Using Java Advanced REST Client

if there is a mahdi The java high level rest client provides a way to search using a term on elasticsearch whose code is shown below SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); sourceBuilder.query(QueryBuilders.termQuery("user", "kimchy"));

ElasticSearch Long Term Query Using Java Advanced REST Client

if there is a mahdi The java high level rest client provides a way to search using a term on elasticsearch whose code is shown below SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); sourceBuilder.query(QueryBuilders.termQuery("user", "kimchy"));

How to handle transport errors in elasticsearch python client?

Hans I'm uploading a pandas dataframe to Elastic (using elasticsearch==6.3.1), it works fine if the dataframe size is less than 100MB, I'm using the solution from How to export pandas data to Elasticsearch ? def rec_to_actions(df): for record in df.to_dict

How to handle transport errors in elasticsearch python client?

Hans I'm uploading a pandas dataframe to Elastic (using elasticsearch==6.3.1), it works fine if the dataframe size is less than 100MB, I'm using the solution from How to export pandas data to Elasticsearch ? def rec_to_actions(df): for record in df.to_dict