Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

elasticsearch - Migrating from Elastic Node Client to Transport or Rest Client

Our current application is running under Spring Boot 1.5 (comes with Elastic Search 2.X)

We use Embedded/In-Memory Elastic search instance and use Node client to connect to the Embedded/In-Memory Elastic instance.

We are looking to migrate away from Embedded Elastic Search to external Elastic Search Instance.

This means we'll need to migrate away from Node Client and use either Transport Client or Low-Level-Rest-Client or High-Level-Rest-Client

Our Spring Boot Config for Node Client looks like this:

@Configuration

    @EnableElasticsearchRepositories
    public class ElasticConfiguration {

        @Bean
        NodeBuilder nodeBuilder(){        return new NodeBuilder();   }

        @Bean
        public ElasticsearchOperations elasticsearchTemplate() throws IOException {

            File tmpDir = File.createTempFile("elastic")                     ); 

     Settings.Builder elasticsearchSettings =  Settings.settingsBuilder()                       
           .put("http.enabled", "true") // 1
           .put("index.number_of_shards", "1")
           .put("path.data", new File(tmpDir, "data").getAbsolutePath()) 
            .put("path.logs", new File(tmpDir, "logs").getAbsolutePath())
            .put("path.work", new File(tmpDir, "work").getAbsolutePath())
            .put("path.home", tmpDir); 
            return new ElasticsearchTemplate(nodeBuilder().local(true)
                    .settings(elasticsearchSettings.build())
                    .node()
                    .client());
        }

Question:

1) If we migrate from Elastic Node client to Elastic Transport client, will it mean heavy code changes for the currently coded Elastic pieces (outside of the elastic config class that creates node client)

2) If we migrate from Node Client to Using Rest Client: i) Again, outside of the Elastic Config code changes, will it mean heavy code changes for the currently coded Elastic pieces? ii) How would the above SpringBoot Elastic Config for Rest client look like? any sample code?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Without any look on your code, based on my experience:

1) should work with minor or no changes at all. But you'll have to go with the rest client as the transport client will be removed soon. Or you'll have work again here in the future.

2i) it depends on the features you are using currently

2ii) please see https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.5/java-rest-high-level-migration.html

I've done many such migrations, many of them are nearly painless. But it really depends on the code of your app. If you can switch to the high-level client there should be just minor changes in your code. But there are also few features missing in the rest client at this moment (you're probably not using). If you need to use the low-level client (due to a jvm version incompatibility) your changes will be a lot more as there is a different approach needed: you need to generate your json for requests and unmarshall the responses.

Please consider your development profile and your tests too. Probably there is an embedded node starting with your application? If so, this needs to be solved in a different way.

If you encounter any migration problems, feel free to come back here again. We'll be here :D


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...