从Elastic Node Client迁移到Transport或Rest Client [英] Migrating from Elastic Node Client to Transport or Rest Client

查看:41
本文介绍了从Elastic Node Client迁移到Transport或Rest Client的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前的应用程序在Spring Boot 1.5下运行(随Elastic Search 2.X一起提供)

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

我们使用嵌入式/内存弹性搜索实例,并使用Node客户端连接到嵌入式/内存弹性实例.

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

我们希望从嵌入式Elastic Search迁移到外部Elastic Search实例.

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

这意味着我们需要从Node Client迁移并使用其中一个运输客户端或低级静态客户端或高级静态客户端

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

我们的Node Client的Spring Boot Config如下所示:

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());
        }

问题:

1)如果我们从Elastic Node客户端迁移到Elastic Transport客户端,这是否意味着当前已编码的Elastic块的代码更改量很大(在创建节点客户端的弹性配置类之外)

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)如果我们从Node Client迁移到Using Rest Client,请执行以下操作:i)同样,在Elastic Config代码更改之外,这是否意味着对当前已编码的Elastic块进行大量代码更改?ii)上面的用于Rest客户端的SpringBoot Elastic Config会是什么样子?任何示例代码?

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?

推荐答案

根据我的经验,您的代码没有任何外观:

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

1)应该进行较小的更改或完全没有更改.但是,您将不得不与其余客户端一起使用,因为传输客户端将很快被删除.否则您将来会在这里再次工作.

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)取决于您当前正在使用的功能

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

2ii),请参见 https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.5/java-rest-high-level-migration.html

我已经做了很多这样的迁移,其中许多迁移几乎没有痛苦.但这实际上取决于您的应用程序的代码.如果您可以切换到高级客户端,则代码中应该只进行了很小的更改.但是目前,其余客户端中还缺少一些功能(您可能没有使用).如果您需要使用低级客户端(由于jvm版本不兼容),您的更改将会更多,因为需要一种不同的方法:您需要为请求生成json并取消对响应的编组.

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.

如果遇到任何迁移问题,请随时再次回到这里.我们将在这里:D

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

这篇关于从Elastic Node Client迁移到Transport或Rest Client的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆